Files
kotlin-fork/compiler/testData/codegen/box/secondaryConstructors/withGenerics.kt
T
Juan Chen 573188bdc4 [FIR2IR]: fix translation of this references in instance methods
Currently FirThisReceiverExpression of instance methods are translated
to references of the class' thisReceiver,
not the method's dispatch receiver,
which causes problems with IrFrameMap::typeOf,
as the class' thisReceiver is not in the typeMap.

This commit translates non-qualified "this" references of
instance methods to references of the methods' dispatch receiver.
2020-01-10 10:43:07 +03:00

38 lines
701 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// FILE: WithGenerics.java
class WithGenerics {
public static String foo1() {
A<Double> x = new A<Double>("OK");
return x.toString();
}
public static String foo2() {
A<Integer> x = new A<Integer>(123);
return x.toString();
}
}
// FILE: WithGenerics.kt
open class A<T> {
val prop: String
constructor(x: String) {
prop = x
}
constructor(x: T) {
prop = x.toString()
}
override fun toString() = prop
}
fun box(): String {
val a1 = WithGenerics.foo1()
if (a1 != "OK") return "fail1: $a1"
val a2 = WithGenerics.foo2()
if (a2 != "123") return "fail2: $a2"
return "OK"
}