[IR][tests] New test: non-abstract callable member in abstract class becomes abstract
^KT-53663
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
package lib1
|
||||
|
||||
interface A {
|
||||
fun foo(): Int = 42
|
||||
fun bar(): Int = 42
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package lib1
|
||||
|
||||
interface A {
|
||||
fun foo(): Int
|
||||
fun bar(): Int
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib
|
||||
modifications:
|
||||
U : l1.kt.0 -> l1.kt
|
||||
STEP 1:
|
||||
dependencies: stdlib
|
||||
modifications:
|
||||
U : l1.kt.1 -> l1.kt
|
||||
STEP 2:
|
||||
dependencies: stdlib
|
||||
modifications:
|
||||
U : l1.kt.0 -> l1.kt
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package lib2
|
||||
|
||||
import lib1.A
|
||||
|
||||
class B : A {
|
||||
override fun bar() = -42
|
||||
|
||||
val unlinkedFunctionUsage get() = foo()
|
||||
}
|
||||
|
||||
class B1 : A {
|
||||
override fun bar() = -42
|
||||
|
||||
val unlinkedFunctionUsage = foo() // Expected failure on class instance initialization.
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import lib1.A
|
||||
import lib2.B
|
||||
import lib2.B1
|
||||
|
||||
fun test1(): String {
|
||||
val a: A = B()
|
||||
return try {
|
||||
val answer: Int = a.foo() // <-- should throw linkage error here
|
||||
println(answer)
|
||||
"FAIL1"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("foo", "B")
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
val a: A = B()
|
||||
val bar = a.bar()
|
||||
return if (bar == -42) "OK" else "bar=$bar"
|
||||
}
|
||||
|
||||
fun test3(): String {
|
||||
val b = B()
|
||||
return try {
|
||||
val answer: Int = b.unlinkedFunctionUsage // <-- should throw linkage error here
|
||||
println(answer)
|
||||
"FAIL2"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("foo", "B")
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(): String {
|
||||
return try {
|
||||
B1()
|
||||
"FAIL3"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("foo", "B1")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = checkResults(test1(), test2(), test3(), test4())
|
||||
|
||||
private fun Throwable.checkLinkageError(symbolName: String, className: String): String {
|
||||
if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}"
|
||||
|
||||
val expectedMessage = "Abstract function $symbolName is not implemented in non-abstract class $className"
|
||||
val actualMessage = message.orEmpty()
|
||||
|
||||
return if (expectedMessage == actualMessage)
|
||||
"OK"
|
||||
else
|
||||
"EXPECTED: $expectedMessage, ACTUAL: $actualMessage"
|
||||
}
|
||||
|
||||
private fun checkResults(vararg results: String): String = when {
|
||||
results.isEmpty() -> "no results to check"
|
||||
results.all { it == "OK" } -> "OK"
|
||||
else -> results.joinToString("\n")
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1, lib2
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
MODULES: lib1, lib2, main
|
||||
|
||||
STEP 0:
|
||||
libs: lib1, lib2, main
|
||||
|
||||
STEP 1:
|
||||
libs: lib1
|
||||
Reference in New Issue
Block a user