Skip to content

Commit

Permalink
Make NamedTuple covariant in its value type
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Dec 3, 2023
1 parent 9826bba commit 3b25712
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import compiletime.ops.boolean.*
object NamedTuple:

opaque type AnyNamedTuple = Any
opaque type NamedTuple[N <: Tuple, V <: Tuple] >: V <: AnyNamedTuple = V
opaque type NamedTuple[N <: Tuple, +V <: Tuple] >: V <: AnyNamedTuple = V

def apply[N <: Tuple, V <: Tuple](x: V) = x

Expand Down
4 changes: 1 addition & 3 deletions tests/neg/named-tuples.check
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
47 | val p5 = person.zip(first = 11, age = 33) // error
| ^^^^^^^^^^^^^^^^^^^^
| Found: (first : Int, age : Int)
| Required: NamedTuple.NamedTuple[(("name" : String), ("age" : String)), V2]
|
| where: V2 is a type variable with constraint <: Tuple
| Required: NamedTuple.NamedTuple[(("name" : String), ("age" : String)), Tuple]
|
| longer explanation available when compiling with `-explain`
-- Warning: tests/neg/named-tuples.scala:24:29 -------------------------------------------------------------------------
Expand Down

0 comments on commit 3b25712

Please sign in to comment.