From 64af4e28ad96866730e4610e375b0dab8ecf58d7 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 31 May 2024 13:48:31 +0200 Subject: [PATCH] make NamedTuple.Empty an alias to NamedTuple --- library/src/scala/NamedTuple.scala | 4 ++-- tests/run/named-tuples.check | 2 ++ tests/run/named-tuples.scala | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/src/scala/NamedTuple.scala b/library/src/scala/NamedTuple.scala index 4c31728d6626..f380fb5528ba 100644 --- a/library/src/scala/NamedTuple.scala +++ b/library/src/scala/NamedTuple.scala @@ -201,10 +201,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 diff --git a/tests/run/named-tuples.check b/tests/run/named-tuples.check index ab1817255336..e36037573090 100644 --- a/tests/run/named-tuples.check +++ b/tests/run/named-tuples.check @@ -9,3 +9,5 @@ Bob is younger than Lucy Bill is younger than Lucy (((Lausanne,Pully),Preverenges),((1003,1009),1028)) 118 +() +(name,age) diff --git a/tests/run/named-tuples.scala b/tests/run/named-tuples.scala index 32c634188d52..b3fa213703af 100644 --- a/tests/run/named-tuples.scala +++ b/tests/run/named-tuples.scala @@ -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: