Skip to content

Commit c1b25d6

Browse files
authored
make NamedTuple.Empty an alias to NamedTuple (#20502)
It was suggested for a follow-up perhaps we should also rename Empty -> EmptyNamedTuple (most code will be doing `import NamedTuple.*`) fixes #20428
2 parents 133c14a + 64af4e2 commit c1b25d6

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

library/src/scala/NamedTuple.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ object NamedTuple:
128128
type From[T] <: AnyNamedTuple
129129

130130
/** The type of the empty named tuple */
131-
type Empty = EmptyTuple.type
131+
type Empty = NamedTuple[EmptyTuple, EmptyTuple]
132132

133133
/** The empty named tuple */
134-
val Empty: Empty = EmptyTuple.asInstanceOf[Empty]
134+
val Empty: Empty = EmptyTuple
135135

136136
end NamedTuple
137137

tests/run/named-tuples.check

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Bob is younger than Lucy
99
Bill is younger than Lucy
1010
(((Lausanne,Pully),Preverenges),((1003,1009),1028))
1111
118
12+
()
13+
(name,age)

tests/run/named-tuples.scala

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ val _: CombinedInfo = bob ++ addr
110110
val totalAge = persons.mapReduce(reducer)
111111
println(totalAge)
112112

113+
inline def namesOf[T <: AnyNamedTuple](t: T): Names[T] = compiletime.constValueTuple[Names[T]]
114+
val namesEmpty = namesOf(NamedTuple.Empty)
115+
val namesBob = namesOf(bob)
116+
val namesEmpty2: EmptyTuple = namesEmpty
117+
val namesBob2: ("name", "age") = namesBob
118+
println(namesEmpty)
119+
println(namesBob)
120+
113121
// testing conversions
114122
object Conv:
115123

0 commit comments

Comments
 (0)