Skip to content

Commit ba2c731

Browse files
authored
fix: Dealias NamedTuple's name types when resolving NamedTuple's element types (#21331)
fixes #21300
2 parents 55ddaec + e4f38d4 commit ba2c731

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeUtils.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class TypeUtils:
129129
def namedTupleElementTypesUpTo(bound: Int, normalize: Boolean = true)(using Context): List[(TermName, Type)] =
130130
(if normalize then self.normalized else self).dealias match
131131
case defn.NamedTuple(nmes, vals) =>
132-
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map:
132+
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
133133
case ConstantType(Constant(str: String)) => str.toTermName
134134
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
135135
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)

tests/pos/i21300.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.language.experimental.namedTuples
2+
3+
class Test[S <: String & Singleton](name: S):
4+
5+
type NT = NamedTuple.NamedTuple[(S, "foo"), (Int, Long)]
6+
def nt: NT = ???
7+
8+
type Name = S
9+
10+
type NT2 = NamedTuple.NamedTuple[(Name, "foo"), (Int, Long)]
11+
def nt2: NT2 = ???
12+
13+
def test =
14+
val foo = new Test("bar")
15+
16+
foo.nt.bar
17+
foo.nt2.bar

0 commit comments

Comments
 (0)