Skip to content

Commit aab80e0

Browse files
committed
Fix #3343: Make baseType work properly with type lambdas
Previously, `C[Char]`.baseTypeOf(`Traversable[Char]`) where C := `[X] => List[X]` returned `Traversable[ParamRef(A)]` instead of `Traversable[Char]`, because the substitution was done on the type parameters of the class symbol instead of the type parameters of the type, these are different when type lambdas are involved. This is fixed by always going through `AppliedType#superType` when the tycon is not a class.
1 parent 0c7aa9d commit aab80e0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,13 +1646,11 @@ object SymDenotations {
16461646
case tp @ AppliedType(tycon, args) =>
16471647
val subsym = tycon.typeSymbol
16481648
if (subsym eq symbol) tp
1649-
else subsym.denot match {
1650-
case clsd: ClassDenotation =>
1651-
val tparams = clsd.typeParams
1652-
if (tparams.hasSameLengthAs(args)) baseTypeOf(tycon).subst(tparams, args)
1653-
else NoType
1654-
case _ =>
1649+
else tycon.typeParams match {
1650+
case LambdaParam(lam, _) :: _ =>
16551651
baseTypeOf(tp.superType)
1652+
case tparams: List[Symbol @unchecked] =>
1653+
baseTypeOf(tycon).subst(tparams, args)
16561654
}
16571655
case tp: TypeProxy =>
16581656
baseTypeOf(tp.superType)

tests/pos/i3343.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def foo[C[_]](implicit t: C[Char] => Traversable[Char]): C[Char] = ???
3+
4+
val a: List[Char] = foo
5+
}

0 commit comments

Comments
 (0)