Skip to content

Commit

Permalink
make NamedTuple.Empty an alias to NamedTuple (#20502)
Browse files Browse the repository at this point in the history
It was suggested for a follow-up perhaps we should also rename Empty ->
EmptyNamedTuple (most code will be doing `import NamedTuple.*`)

fixes #20428
  • Loading branch information
odersky authored Jun 18, 2024
2 parents 133c14a + 64af4e2 commit c1b25d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ object NamedTuple:
type From[T] <: AnyNamedTuple

/** The type of the empty named tuple */
type Empty = EmptyTuple.type
type Empty = NamedTuple[EmptyTuple, EmptyTuple]

/** The empty named tuple */
val Empty: Empty = EmptyTuple.asInstanceOf[Empty]
val Empty: Empty = EmptyTuple

end NamedTuple

Expand Down
2 changes: 2 additions & 0 deletions tests/run/named-tuples.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Bob is younger than Lucy
Bill is younger than Lucy
(((Lausanne,Pully),Preverenges),((1003,1009),1028))
118
()
(name,age)
8 changes: 8 additions & 0 deletions tests/run/named-tuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ val _: CombinedInfo = bob ++ addr
val totalAge = persons.mapReduce(reducer)
println(totalAge)

inline def namesOf[T <: AnyNamedTuple](t: T): Names[T] = compiletime.constValueTuple[Names[T]]
val namesEmpty = namesOf(NamedTuple.Empty)
val namesBob = namesOf(bob)
val namesEmpty2: EmptyTuple = namesEmpty
val namesBob2: ("name", "age") = namesBob
println(namesEmpty)
println(namesBob)

// testing conversions
object Conv:

Expand Down

0 comments on commit c1b25d6

Please sign in to comment.