diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 252d84638787..4063eddf4a55 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -507,7 +507,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean // constructor method should not be semi-erased. else if (isConstructor && isDerivedValueClass(sym)) eraseNormalClassRef(tp) else this(tp) - case AppliedType(tycon, _) if !erasureDependsOnArgs(tycon) => + case AppliedType(tycon, _) if tycon.typeSymbol.isClass && !erasureDependsOnArgs(tycon) => eraseResult(tycon) case _ => this(tp) diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala index 87cfdd764218..598c6e9de05b 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala @@ -450,4 +450,29 @@ class TestBCode extends DottyBytecodeTest { } } + /** Test that type lambda applications are properly dealias */ + @Test def i5090 = { + val source = + """class Test { + | type T[X] = X + | + | def test(i: T[Int]): T[Int] = i + | def ref(i: Int): Int = i + |} + """.stripMargin + + checkBCode(source) { dir => + val clsIn = dir.lookupName("Test.class", directory = false).input + val clsNode = loadClassNode(clsIn) + val test = getMethod(clsNode, "test") + val ref = getMethod(clsNode, "ref") + + val testInstructions = instructionsFromMethod(test) + val refInstructions = instructionsFromMethod(ref) + + assert(testInstructions == refInstructions, + "`T[Int]` was not properly dealias" + + diffInstructions(testInstructions, refInstructions)) + } + } } diff --git a/tests/pos/i5090.scala b/tests/pos/i5090.scala new file mode 100644 index 000000000000..7b5121a8d508 --- /dev/null +++ b/tests/pos/i5090.scala @@ -0,0 +1,4 @@ +class TypeAlias { + type T[X] = X + def a(i: T[Int]): T[Int] = i +}