Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete for elements of a NamedTuple #397

Open
t9dupuy opened this issue Sep 4, 2024 · 3 comments
Open

Autocomplete for elements of a NamedTuple #397

t9dupuy opened this issue Sep 4, 2024 · 3 comments

Comments

@t9dupuy
Copy link

t9dupuy commented Sep 4, 2024

Is your feature request related to a problem? Please describe.

Elements of a NamedTuple do not appear in the suggested members/methods dropdown.

Describe the solution you'd like

The elements of a NamedTuple should be suggested for autocompletion just like the members of a class or the elements of a regular tuple (_1, _2...)

For example:

val nt = (integer = 0, string = "hello")

both integer and string should be suggested when writing nt.

Describe alternatives you've considered

n/a

Additional context

No response

Search terms

namedtuple

@dragove
Copy link

dragove commented Sep 15, 2024

I've noticed that the type of named tuple is odd. when I ask the type of named tuple in the following variable x

val x = (name = "Dove", age = 233)

it shows

Expression type:
(name : String, age : Int)
Symbol signature:
val x: (name : String, age : Int)

but if I ask the type of x in following context

println(x.name) // note: the .name should be here to reproduce this behavior

it shows

Expression type:
Elem[(String, Int), 0]
Symbol signature:
extension [N <: Tuple, V <: Tuple](x: V) inline def apply(n: Int): Elem[V, n.type]

I don't know if it is expected or a bug.

@t9dupuy
Copy link
Author

t9dupuy commented Sep 16, 2024

I believe this is expected. Dot notation (.name) on namedtuples is just a syntactic trick desugarized by the compiler to a method call (here .apply(0)).

Implementation: https://github.com/scala/scala3/blob/f539112a9fa70a5574545a30457261b69c6e844d/library/src/scala/NamedTuple.scala#L144

@tgodzik
Copy link
Contributor

tgodzik commented Sep 16, 2024

Looks like that could be improved though also. I think it's just a missing case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants