Open t9dupuy opened 2 weeks ago
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.
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
Looks like that could be improved though also. I think it's just a missing case.
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:
both
integer
andstring
should be suggested when writingnt.
Describe alternatives you've considered
n/a
Additional context
No response
Search terms
namedtuple