Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dealias NamedTuple's name types when resolving NamedTuple's element types #21331

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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