[IR][tests] New test: non-abstract callable member in abstract class becomes abstract
^KT-53663
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
package lib1
|
||||
|
||||
abstract class A {
|
||||
fun foo(): Int = 42
|
||||
open fun bar(): Int = 42
|
||||
open fun baz(): Int = 42
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package lib1
|
||||
|
||||
abstract class A {
|
||||
abstract fun foo(): Int
|
||||
abstract fun bar(): Int
|
||||
abstract fun baz(): Int
|
||||
}
|
||||
Vendored
+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
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package lib2
|
||||
|
||||
import lib1.A
|
||||
|
||||
class B : A() {
|
||||
override fun baz() = -42
|
||||
|
||||
val unlinkedFunctionUsage get() = foo() + bar()
|
||||
}
|
||||
|
||||
class B1 : A() {
|
||||
override fun baz() = -42
|
||||
|
||||
val unlinkedFunctionUsage = foo() // Expected failure on class instance initialization.
|
||||
}
|
||||
|
||||
class B2 : A() {
|
||||
override fun baz() = -42
|
||||
|
||||
val unlinkedFunctionUsage = bar() // Expected failure on class instance initialization.
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import lib1.A
|
||||
import lib2.B
|
||||
import lib2.B1
|
||||
import lib2.B2
|
||||
|
||||
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()
|
||||
return try {
|
||||
val answer: Int = a.bar() // <-- should throw linkage error here
|
||||
println(answer)
|
||||
"FAIL2"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("bar", "B")
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(): String {
|
||||
val a: A = B()
|
||||
val baz = a.baz()
|
||||
return if (baz == -42) "OK" else "baz=$baz"
|
||||
}
|
||||
|
||||
fun test4(): String {
|
||||
val b = B()
|
||||
return try {
|
||||
val answer: Int = b.unlinkedFunctionUsage // <-- should throw linkage error here
|
||||
println(answer)
|
||||
"FAIL3"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("foo", "B")
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(): String {
|
||||
return try {
|
||||
B1()
|
||||
"FAIL4"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("foo", "B1")
|
||||
}
|
||||
}
|
||||
|
||||
fun test6(): String {
|
||||
return try {
|
||||
B2()
|
||||
"FAIL5"
|
||||
} catch (e: Throwable) {
|
||||
e.checkLinkageError("bar", "B2")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = checkResults(test1(), test2(), test3(), test4(), test5(), test6())
|
||||
|
||||
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")
|
||||
}
|
||||
Vendored
+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