Skip to content

Commit f5a6b74

Browse files
authored
Merge pull request #5091 from dotty-staging/fix-#5090
Fix #5090: Fix condition in erasedResult type
2 parents 00e396c + 98396ad commit f5a6b74

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
507507
// constructor method should not be semi-erased.
508508
else if (isConstructor && isDerivedValueClass(sym)) eraseNormalClassRef(tp)
509509
else this(tp)
510-
case AppliedType(tycon, _) if !erasureDependsOnArgs(tycon) =>
510+
case AppliedType(tycon, _) if tycon.typeSymbol.isClass && !erasureDependsOnArgs(tycon) =>
511511
eraseResult(tycon)
512512
case _ =>
513513
this(tp)

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,29 @@ class TestBCode extends DottyBytecodeTest {
450450
}
451451
}
452452

453+
/** Test that type lambda applications are properly dealias */
454+
@Test def i5090 = {
455+
val source =
456+
"""class Test {
457+
| type T[X] = X
458+
|
459+
| def test(i: T[Int]): T[Int] = i
460+
| def ref(i: Int): Int = i
461+
|}
462+
""".stripMargin
463+
464+
checkBCode(source) { dir =>
465+
val clsIn = dir.lookupName("Test.class", directory = false).input
466+
val clsNode = loadClassNode(clsIn)
467+
val test = getMethod(clsNode, "test")
468+
val ref = getMethod(clsNode, "ref")
469+
470+
val testInstructions = instructionsFromMethod(test)
471+
val refInstructions = instructionsFromMethod(ref)
472+
473+
assert(testInstructions == refInstructions,
474+
"`T[Int]` was not properly dealias" +
475+
diffInstructions(testInstructions, refInstructions))
476+
}
477+
}
453478
}

tests/pos/i5090.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class TypeAlias {
2+
type T[X] = X
3+
def a(i: T[Int]): T[Int] = i
4+
}

0 commit comments

Comments
 (0)