Skip to content

Fix #5090: Fix condition in erasedResult type #5091

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

Merged
merged 2 commits into from
Sep 9, 2018
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/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
4 changes: 4 additions & 0 deletions tests/pos/i5090.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class TypeAlias {
type T[X] = X
def a(i: T[Int]): T[Int] = i
}