Skip to content

Commit 32e4056

Browse files
Move NamedTuple.head to NamedTupleDecomposition
This is in particular necessary for #21291, to avoid problems encountered after inlining from scopes defining opaque types (such as in the example below), as was already done for the other NamedTuple operations in #20504. ```scala -- Error: tests/pos/named-tuple-combinators.scala:46:17 ------------------------ 46 | val res1 = x.head | ^^^^^^ |(Int, String) does not conform to bound >: | (x$proxy55 : (x : Test.NT) & | $proxy19.NamedTuple[ | Tuple.Concat[ | NamedTupleDecomposition.Names[ | $proxy19.NamedTuple[Tuple1[("hi" : String)], Tuple1[Int]]], | NamedTupleDecomposition.Names[ | $proxy19.NamedTuple[Tuple1[("bla" : String)], Tuple1[String]]] | ], | Tuple.Concat[ | NamedTupleDecomposition.DropNames[ | $proxy19.NamedTuple[Tuple1[("hi" : String)], Tuple1[Int]]], | NamedTupleDecomposition.DropNames[ | $proxy19.NamedTuple[Tuple1[("bla" : String)], Tuple1[String]]] | ] | ] | ) | <: Tuple |---------------------------------------------------------------------------- |Inline stack trace |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |This location contains code that was inlined from NamedTuple.scala:47 47 | inline def head: Tuple.Elem[V, 0] = x.apply(0) | ^^^^^^^ ---------------------------------------------------------------------------- ```
1 parent 3dfd762 commit 32e4056

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: library/src/scala/NamedTuple.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object NamedTuple:
3030

3131
export NamedTupleDecomposition.{
3232
Names, DropNames,
33-
apply, size, init, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray
33+
apply, size, init, head, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray
3434
}
3535

3636
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])
@@ -43,9 +43,6 @@ object NamedTuple:
4343
// and should be reverted, just like NonEmptyList is also appealing at first, but a bad idea
4444
// in the end.
4545

46-
/** The first element value of this tuple */
47-
inline def head: Tuple.Elem[V, 0] = x.apply(0)
48-
4946
// inline def :* [L] (x: L): NamedTuple[Append[N, ???], Append[V, L] = ???
5047
// inline def *: [H] (x: H): NamedTuple[??? *: N], H *: V] = ???
5148

@@ -149,6 +146,9 @@ object NamedTupleDecomposition:
149146
/** The number of elements in this tuple */
150147
inline def size: Tuple.Size[V] = x.toTuple.size
151148

149+
/** The first element value of this tuple */
150+
inline def head: Tuple.Elem[V, 0] = apply(0)
151+
152152
/** The last element value of this tuple */
153153
inline def last: Tuple.Last[V] = apply(size - 1).asInstanceOf[Tuple.Last[V]]
154154

0 commit comments

Comments
 (0)