mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Compatibility warning for references to companion via name (KT-13934)
(cherry picked from commit 718f23b34f)
This commit is contained in:
32
compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt
vendored
Normal file
32
compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
fun foo(): String = "Fail"
|
||||
}
|
||||
}
|
||||
|
||||
fun B.foo(): String = "OK"
|
||||
|
||||
fun call(f: Any): String = if (f is Function0<*>) f.invoke() as String else (f as Function1<B, String>).invoke(B())
|
||||
|
||||
fun box(): String {
|
||||
val call1 = call(A::foo)
|
||||
if (call1 != "OK") return "fail 1: $call1"
|
||||
|
||||
// Checking compatibility mode: should be resolved to extensions in 1.4
|
||||
val call2 = call(B::foo)
|
||||
if (call2 != "OK") return "fail 2: $call2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user