Skip to content

Commit

Permalink
Backport "fix: Dealias NamedTuple's name types when resolving NamedTu…
Browse files Browse the repository at this point in the history
…ple's element types" to 3.5.2 (#21486)

Backports #21331 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Aug 28, 2024
2 parents c7df242 + 18c6484 commit da117c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TypeUtils:
def namedTupleElementTypesUpTo(bound: Int, normalize: Boolean = true)(using Context): List[(TermName, Type)] =
(if normalize then self.normalized else self).dealias match
case defn.NamedTuple(nmes, vals) =>
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map:
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
case ConstantType(Constant(str: String)) => str.toTermName
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i21300.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import scala.language.experimental.namedTuples

class Test[S <: String & Singleton](name: S):

type NT = NamedTuple.NamedTuple[(S, "foo"), (Int, Long)]
def nt: NT = ???

type Name = S

type NT2 = NamedTuple.NamedTuple[(Name, "foo"), (Int, Long)]
def nt2: NT2 = ???

def test =
val foo = new Test("bar")

foo.nt.bar
foo.nt2.bar

0 comments on commit da117c7

Please sign in to comment.