[Test] Add regression tests for issues which are fixed in K2

Related issues:
KT-10879, KT-18055, KT-20617, KT-23873
KT-25668, KT-31191, KT-33108, KT-41013
KT-51827, KT-53886, KT-56624, KT-58447
KT-58458, KT-58751, KT-58814, KT-60597
KT-62806, KT-63258, KT-63444, KT-65101
KT-65408, KT-65844, KT-66186

^KT-65926 Fixed
This commit is contained in:
Dmitriy Novozhilov
2024-02-28 12:13:45 +02:00
committed by Space Team
parent b875ae774e
commit 4b5eac7816
79 changed files with 1719 additions and 0 deletions
@@ -0,0 +1,27 @@
// LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// ISSUE: KT-52887
interface SnarkRoute {
context(PageContext)
fun route(route: String, block: context(PageContext, SnarkRoute) () -> Unit)
}
context(PageContext)
fun SnarkRoute.pagesFrom() {
route("") {
get {
}
}
}
data class PageContext(val context: String)
fun SnarkRoute.get(foo: ()-> Unit) {}
fun box(): String {
return "OK"
}
@@ -0,0 +1,10 @@
// WITH_STDLIB
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6, WASM, NATIVE
// ISSUE: KT-62806
fun <T: Number> foo(x: Number) = x as? T ?: TODO()
val x: Int? = foo<Int>(1)
fun box(): String {
return if (x == 1) "OK" else "Fail: $x"
}
@@ -0,0 +1,25 @@
// IGNORE_BACKEND_K1: ANY
// WITH_STDLIB
// ISSUE: KT-63258
class MethodReferenceNPE() {
private val singleRef: () -> Unit =
1.let {
if (it == 0) {
{ }
} else {
this@MethodReferenceNPE::myMethod
}
}
private fun myMethod() {}
fun run() {
singleRef()
}
}
fun box(): String {
MethodReferenceNPE().run()
return "OK"
}
@@ -0,0 +1,14 @@
// ISSUE: KT-65844
@RequiresOptIn
annotation class MyOptIn
@MyOptIn
fun foo() {}
@OptIn(markerClass = [MyOptIn::class]) // should be ok
class MyClass {
fun test() {
foo()
}
}
@@ -0,0 +1,14 @@
// ISSUE: KT-65844
@RequiresOptIn
annotation class MyOptIn
@MyOptIn
fun foo() {}
@OptIn(markerClass = [<!OPT_IN_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_OPT_IN!>MyOptIn<!>::class]) // should be ok
class MyClass {
fun test() {
foo()
}
}
@@ -0,0 +1 @@
java.lang.AssertionError: Recursion detected on input: component2
@@ -0,0 +1,5 @@
// FIR_IDENTICAL
// WITH_STDLIB
// ISSUE: KT-58447
fun @ParameterName(<!UNRESOLVED_REFERENCE!>component2<!>) Int.component2() = this + 2
@@ -0,0 +1,10 @@
// ISSUE: KT-33108
// FULL_JDK
import java.util.Optional
open class A
class B : A()
fun useOptional(): A {
return Optional.of(0).map { B() as A }.orElse(A())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-33108
// FULL_JDK
import java.util.Optional
open class A
class B : A()
fun useOptional(): A {
return Optional.of(0).map { B() <!USELESS_CAST!>as A<!> }.orElse(A())
}
@@ -0,0 +1,15 @@
// ISSUE: KT-23873
// WITH_STDLIB
data class Holder<T>(val data: T)
val data: Map<Holder<Holder<*>>, Int> = null!!
val test = Holder(Holder(1))
fun test_1() {
data.get(test as Holder<*>)
}
fun test_2() {
data[test as Holder<*>]
}
@@ -0,0 +1,15 @@
// ISSUE: KT-23873
// WITH_STDLIB
data class Holder<T>(val data: T)
val data: Map<Holder<Holder<*>>, Int> = null!!
val test = Holder(Holder(1))
fun test_1() {
data.get(test as Holder<*>)
}
fun test_2() {
data[test <!USELESS_CAST!>as Holder<*><!>]
}
@@ -0,0 +1,7 @@
// ISSUE: KT-65408
data object CreateBuilder : Builder<CreateBuilder> {
fun foo(): CreateBuilder = <!UNRESOLVED_REFERENCE!>copy<!>() // should be an error
}
interface Builder<T> : Cloneable
@@ -0,0 +1,7 @@
// ISSUE: KT-65408
data object CreateBuilder : Builder<CreateBuilder> {
fun foo(): CreateBuilder = copy() // should be an error
}
interface Builder<T> : Cloneable
@@ -0,0 +1,8 @@
// ISSUE: KT-58751
class Result<out T>
interface Convert<T> {
fun convert(str: String): Result<T & Any>
}
fun Convert<*>.cnv(value: String): Result<Any> = convert(value)
@@ -0,0 +1,8 @@
// ISSUE: KT-58751
class Result<out T>
interface Convert<T> {
fun convert(str: String): Result<T & Any>
}
fun Convert<*>.cnv(value: String): Result<Any> = <!TYPE_MISMATCH!>convert(value)<!>
@@ -0,0 +1,5 @@
// ISSUE: KT-56624
import A as B
enum class A {
E()
}
@@ -0,0 +1,5 @@
// ISSUE: KT-56624
import A as B
enum class A {
E<!UNRESOLVED_REFERENCE!><!>()
}
@@ -0,0 +1,37 @@
// ISSUE: KT-65101
// WITH_STDLIB
interface Context<C: Context<C>>
interface InterfaceA<C: Context<C>>
class ABuilder<C: Context<C>, A: InterfaceA<C>, B: InterfaceA<C>>
operator fun <C, A, B> ABuilder<C, A, B>.invoke(block: B.() -> Unit): Unit
where C: Context<C>,
A: InterfaceA<C>,
B: InterfaceA<C>
= null!!
object ContextImpl : Context<ContextImpl>
object RootA : InterfaceA<ContextImpl>
class AImpl<P: Context<P>> : InterfaceA<P> {
fun foo(): Int = null!!
}
val <C: Context<C>, A: InterfaceA<C>> A.impl get() = ABuilder<C, A, AImpl<C>>()
fun test_1() {
RootA.apply {
(impl) {
foo()
}
}
}
fun test_2() {
RootA.apply {
impl {
foo()
}
}
}
@@ -0,0 +1,37 @@
// ISSUE: KT-65101
// WITH_STDLIB
interface Context<C: Context<C>>
interface InterfaceA<C: Context<C>>
class ABuilder<C: Context<C>, A: InterfaceA<C>, B: InterfaceA<C>>
operator fun <C, A, B> ABuilder<C, A, B>.invoke(block: B.() -> Unit): Unit
where C: Context<C>,
A: InterfaceA<C>,
B: InterfaceA<C>
= null!!
object ContextImpl : Context<ContextImpl>
object RootA : InterfaceA<ContextImpl>
class AImpl<P: Context<P>> : InterfaceA<P> {
fun foo(): Int = null!!
}
val <C: Context<C>, A: InterfaceA<C>> A.impl get() = ABuilder<C, A, AImpl<C>>()
fun test_1() {
RootA.apply {
(impl) {
foo()
}
}
}
fun test_2() {
RootA.apply {
impl {
<!UNRESOLVED_REFERENCE!>foo<!>()
}
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-66186
// WITH_STDLIB
// FULL_JDK
fun test() {
val list = listOf("asd", "sda")
list.stream()
.filter(String::isNotEmpty)
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>collect<!>(<!UNRESOLVED_REFERENCE!>FakeClass<!>.toList())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-66186
// WITH_STDLIB
// FULL_JDK
fun test() {
val list = listOf("asd", "sda")
list.stream()
.filter(String::isNotEmpty)
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>collect<!>(<!UNRESOLVED_REFERENCE!>FakeClass<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>toList<!>())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-63444
class A<D : Any> {
inner class Ainner<DD : D?> {
fun innerFun() {}
}
fun test(w:Ainner<*>) {
w.innerFun()
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-63444
class A<D : Any> {
inner class Ainner<DD : D?> {
fun innerFun() {}
}
fun test(w:Ainner<*>) {
w.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>innerFun<!>()
}
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-20617
fun Int.function() = run {
this@function + 1
}
val Int.property1: Int
get() {
return run { this@property1 + 1 }
}
val Int.property2 get() = run {
this@property2 + 1
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-20617
fun Int.function() = run {
this@function + 1
}
val Int.property1: Int
get() {
return run { this@property1 + 1 }
}
val Int.property2 get() = run {
this<!UNRESOLVED_REFERENCE!>@property2<!> <!DEBUG_INFO_MISSING_UNRESOLVED!>+<!> 1
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-41013
fun <V, R> Iterable<V>.map(transform: (V) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v) }
}
fun <V, R> Iterable<V>.map(transform: (V, Int) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v, i) }
}
fun main() {
val list = listOf(1, 2, 3)
println(list.map { v -> v })
println(list.map { it })
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-41013
fun <V, R> Iterable<V>.map(transform: (V) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v) }
}
fun <V, R> Iterable<V>.map(transform: (V, Int) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v, i) }
}
fun main() {
val list = listOf(1, 2, 3)
println(list.map { v -> v })
println(list.<!OVERLOAD_RESOLUTION_AMBIGUITY!>map<!> { <!UNRESOLVED_REFERENCE!>it<!> })
}
@@ -0,0 +1,20 @@
// ISSUE: KT-51827
abstract class A {
abstract protected val a: Any?
open class Nested(override val a: String) : A() {
class B {
fun f(other: A) {
other.a
if (other is Nested) {
other.a.length
}
if (other is C) {
other.a
}
}
}
}
class C(override val a: String): Nested(a)
}
@@ -0,0 +1,20 @@
// ISSUE: KT-51827
abstract class A {
abstract protected val a: Any?
open class Nested(override val a: String) : A() {
class B {
fun f(other: A) {
other.a
if (other is Nested) {
<!DEBUG_INFO_SMARTCAST!>other<!>.a.length
}
if (other is C) {
<!DEBUG_INFO_SMARTCAST!>other<!>.<!INVISIBLE_MEMBER!>a<!>
}
}
}
}
class C(override val a: String): Nested(a)
}
@@ -0,0 +1,16 @@
// FULL_JDK
// WITH_REFLECT
// ISSUE: KT-58814
open class A
class B : A()
class C : A()
fun <T : A> createObj(implementedBy: Class<T>): T {
val obj = when (implementedBy) {
B::class.java -> B()
else -> throw Exception("unsupported class")
}
val castObj = implementedBy.cast(obj)
return castObj // should be OK
}
@@ -0,0 +1,16 @@
// FULL_JDK
// WITH_REFLECT
// ISSUE: KT-58814
open class A
class B : A()
class C : A()
fun <T : A> createObj(implementedBy: Class<T>): T {
val obj = when (implementedBy) {
B::class.java -> B()
else -> throw Exception("unsupported class")
}
val castObj = <!DEBUG_INFO_SMARTCAST!>implementedBy<!>.cast(obj)
return <!TYPE_MISMATCH!>castObj<!> // should be OK
}
@@ -0,0 +1,17 @@
// ISSUE: KT-10879
// FILE: A.java
public interface A {
A getFoo();
}
// FILE: main.kt
interface B : A
interface C : A
fun test(x: A) {
if (x !is C) return
if (x is B) {
x.foo.foo
x.getFoo().foo
}
}
@@ -0,0 +1,17 @@
// ISSUE: KT-10879
// FILE: A.java
public interface A {
A getFoo();
}
// FILE: main.kt
interface B : A
interface C : A
fun test(x: A) {
if (x !is C) return
if (x is B) {
x.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!>
x.getFoo().foo
}
}
@@ -0,0 +1,13 @@
// ISSUE: KT-18055
fun main() {
data class Stat(val link: String? = null)
var stat = Stat()
if (stat.link != null) {
takeString(stat.link)
}
}
fun takeString(link: String) {}
@@ -0,0 +1,13 @@
// ISSUE: KT-18055
fun main() {
data class Stat(val link: String? = null)
var stat = Stat()
if (stat.link != null) {
takeString(<!SMARTCAST_IMPOSSIBLE!>stat.link<!>)
}
}
fun takeString(link: String) {}
@@ -0,0 +1,5 @@
java.lang.IllegalArgumentException: fromIndex(0) > toIndex(-1)
at java.util.ArrayList.subListRangeCheck(ArrayList.java:1016)
at java.util.ArrayList.subList(ArrayList.java:1006)
at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.quickResolveToPackage(QualifiedExpressionResolver.kt:708)
at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.resolveToPackageOrClassPrefix(QualifiedExpressionResolver.kt:527)
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
// ISSUE: KT-60597
fun test() {
<!UNRESOLVED_REFERENCE!>`java.lang.Short.TYPE`<!>.getConstructor(TODO())
}
@@ -0,0 +1,4 @@
java.lang.NullPointerException
at org.jetbrains.kotlin.types.expressions.PatternMatchingTypingVisitor$Subject$Variable.makeValueArgument(PatternMatchingTypingVisitor.kt:149)
at org.jetbrains.kotlin.types.expressions.PatternMatchingTypingVisitor$checkWhenCondition$1.visitWhenConditionInRange(PatternMatchingTypingVisitor.kt:509)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitWhenConditionInRange(KtVisitorVoid.java:1015)
@@ -0,0 +1,8 @@
// FIR_IDENTICAL
// ISSUE: KT-58458
fun box() =
when (val<!SYNTAX!><!> = <!UNRESOLVED_REFERENCE!>x<!>) {
in <!UNRESOLVED_REFERENCE!>y<!> -> ""
else -> ""
}
@@ -0,0 +1,14 @@
// ISSUE: KT-31191
import kotlin.contracts.*
@OptIn(ExperimentalContracts::class)
fun Any.isString(): Boolean {
contract { returns(true) implies (this@isString is String) }
return this is String
}
fun test(x: Any?) {
if (x != null && x.isString()) {
x.length
}
}
@@ -0,0 +1,14 @@
// ISSUE: KT-31191
import kotlin.contracts.*
@OptIn(ExperimentalContracts::class)
fun Any.isString(): Boolean {
contract { returns(true) implies (this@isString is String) }
return this is String
}
fun test(x: Any?) {
if (x != null && <!DEBUG_INFO_SMARTCAST!>x<!>.isString()) {
x.<!UNRESOLVED_REFERENCE!>length<!>
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-25668
suspend fun SequenceScope<Int>.bar() = yield(1)
fun test() {
val seq = sequence {
val f: suspend SequenceScope<Int>.() -> Unit = SequenceScope<Int>::bar
f()
}
seq.toList()
}
@@ -0,0 +1,10 @@
// ISSUE: KT-25668
suspend fun SequenceScope<Int>.bar() = yield(1)
fun test() {
val seq = sequence {
val f: suspend SequenceScope<Int>.() -> Unit = SequenceScope<Int>::<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>bar<!>
f()
}
seq.toList()
}
@@ -0,0 +1,48 @@
FILE fqName:<root> fileName:/test.kt
PROPERTY name:key visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:key type:<root>.A.Key<kotlin.Boolean> visibility:private [final,static]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.A.Key' type=<root>.A.Key<kotlin.Boolean> origin=null
<class: T>: kotlin.Boolean
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-key> visibility:public modality:FINAL <> () returnType:<root>.A.Key<kotlin.Boolean>
correspondingProperty: PROPERTY name:key visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-key> (): <root>.A.Key<kotlin.Boolean> declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:key type:<root>.A.Key<kotlin.Boolean> visibility:private [final,static]' type=<root>.A.Key<kotlin.Boolean> origin=null
PROPERTY name:x visibility:public modality:FINAL [delegated,val]
FIELD PROPERTY_DELEGATE name:x$delegate type:kotlin.Lazy<kotlin.Boolean> visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<kotlin.Boolean> origin=null
<T>: kotlin.Boolean
initializer: FUN_EXPR type=kotlin.Function0<kotlin.Boolean> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Boolean
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Boolean declared in <root>.x$delegate'
BLOCK type=kotlin.Boolean origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:@[EnhancedNullability] kotlin.Boolean? [val]
CALL 'public open fun get <T> (key: @[EnhancedNullability] <root>.A.Key<@[FlexibleNullability] T of <root>.A.get?>): @[EnhancedNullability] T of <root>.A.get? declared in <root>.A' type=@[EnhancedNullability] kotlin.Boolean? origin=null
<T>: @[FlexibleNullability] kotlin.Boolean?
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.A' type=<root>.A origin=null
key: CALL 'public final fun <get-key> (): <root>.A.Key<kotlin.Boolean> declared in <root>' type=<root>.A.Key<kotlin.Boolean> origin=GET_PROPERTY
WHEN type=kotlin.Boolean origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: @[EnhancedNullability] kotlin.Boolean? declared in <root>.x$delegate.<anonymous>' type=@[EnhancedNullability] kotlin.Boolean? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Boolean type=kotlin.Boolean value=false
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_0: @[EnhancedNullability] kotlin.Boolean? declared in <root>.x$delegate.<anonymous>' type=@[EnhancedNullability] kotlin.Boolean? origin=null
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> () returnType:kotlin.Boolean
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [delegated,val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): kotlin.Boolean declared in <root>'
CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.getValue declared in kotlin' type=kotlin.Boolean origin=null
<T>: kotlin.Boolean
$receiver: GET_FIELD 'FIELD PROPERTY_DELEGATE name:x$delegate type:kotlin.Lazy<kotlin.Boolean> visibility:private [final,static]' type=kotlin.Lazy<kotlin.Boolean> origin=null
thisRef: CONST Null type=kotlin.Nothing? value=null
property: PROPERTY_REFERENCE 'public final x: kotlin.Boolean' field=null getter='public final fun <get-x> (): kotlin.Boolean declared in <root>' setter=null type=kotlin.reflect.KProperty0<kotlin.Boolean> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public final fun println (message: kotlin.Boolean): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null
message: CALL 'public final fun <get-x> (): kotlin.Boolean declared in <root>' type=kotlin.Boolean origin=GET_PROPERTY
@@ -0,0 +1,22 @@
val key: Key<Boolean>
field = Key<Boolean>()
get
val x: Boolean /* by */
field = lazy<Boolean>(initializer = local fun <anonymous>(): Boolean {
return { // BLOCK
val tmp_0: @EnhancedNullability Boolean? = A().get<@FlexibleNullability Boolean?>(key = <get-key>())
when {
EQEQ(arg0 = tmp_0, arg1 = null) -> false
else -> tmp_0
}
}
}
)
get(): Boolean {
return #x$delegate.getValue<Boolean>(thisRef = null, property = ::x)
}
fun main() {
println(message = <get-x>())
}
@@ -0,0 +1,29 @@
// CHECK:
// Mangled name: {}key
// Public signature: /key|1144547298251177939[0]
// Public signature debug description: {}key
val key: Key<Boolean>
// CHECK JVM_IR:
// Mangled name: #<get-key>(){}A.Key<kotlin.Boolean>
// Public signature: /key.<get-key>|-6107443460337397211[0]
// Public signature debug description: <get-key>(){}A.Key<kotlin.Boolean>
get
// CHECK:
// Mangled name: {}x
// Public signature: /x|-8060530855978347579[0]
// Public signature debug description: {}x
val x: Boolean /* by */
// CHECK JVM_IR:
// Mangled name: #<get-x>(){}kotlin.Boolean
// Public signature: /x.<get-x>|1798055433828515329[0]
// Public signature debug description: <get-x>(){}kotlin.Boolean
get(): Boolean
// CHECK JVM_IR:
// Mangled name: #main(){}
// Mangled name for the signature by IR: main(){}
// Mangled name for the signature by Frontend: main(){}%test.kt
// Public signature: /main|-4284757841571462650[0]
// Public signature debug description: main(){}
fun main(): Unit
@@ -0,0 +1,49 @@
FILE fqName:<root> fileName:/test.kt
PROPERTY name:key visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:key type:<root>.A.Key<kotlin.Boolean> visibility:private [final,static]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.A.Key' type=<root>.A.Key<kotlin.Boolean> origin=null
<class: T>: @[FlexibleNullability] kotlin.Boolean?
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-key> visibility:public modality:FINAL <> () returnType:<root>.A.Key<kotlin.Boolean>
correspondingProperty: PROPERTY name:key visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-key> (): <root>.A.Key<kotlin.Boolean> declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:key type:<root>.A.Key<kotlin.Boolean> visibility:private [final,static]' type=<root>.A.Key<kotlin.Boolean> origin=null
PROPERTY name:x visibility:public modality:FINAL [delegated,val]
FIELD PROPERTY_DELEGATE name:x$delegate type:kotlin.Lazy<@[EnhancedNullability] kotlin.Boolean> visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<@[EnhancedNullability] kotlin.Boolean> origin=null
<T>: @[EnhancedNullability] kotlin.Boolean
initializer: FUN_EXPR type=kotlin.Function0<@[EnhancedNullability] kotlin.Boolean> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:@[EnhancedNullability] kotlin.Boolean
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): @[EnhancedNullability] kotlin.Boolean declared in <root>.x$delegate'
BLOCK type=@[EnhancedNullability] kotlin.Boolean origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:@[EnhancedNullability] kotlin.Boolean? [val]
CALL 'public open fun get <T> (key: @[EnhancedNullability] <root>.A.Key<@[FlexibleNullability] T of <root>.A.get?>): @[EnhancedNullability] T of <root>.A.get? declared in <root>.A' type=@[EnhancedNullability] kotlin.Boolean? origin=null
<T>: @[FlexibleNullability] kotlin.Boolean?
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.A' type=<root>.A origin=null
key: CALL 'public final fun <get-key> (): <root>.A.Key<kotlin.Boolean> declared in <root>' type=<root>.A.Key<kotlin.Boolean> origin=GET_PROPERTY
WHEN type=@[EnhancedNullability] kotlin.Boolean origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: @[EnhancedNullability] kotlin.Boolean? declared in <root>.x$delegate.<anonymous>' type=@[EnhancedNullability] kotlin.Boolean? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Boolean type=kotlin.Boolean value=false
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_0: @[EnhancedNullability] kotlin.Boolean? declared in <root>.x$delegate.<anonymous>' type=@[EnhancedNullability] kotlin.Boolean? origin=null
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> () returnType:@[EnhancedNullability] kotlin.Boolean
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [delegated,val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): @[EnhancedNullability] kotlin.Boolean declared in <root>'
CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.getValue declared in kotlin' type=@[EnhancedNullability] kotlin.Boolean origin=null
<T>: @[EnhancedNullability] kotlin.Boolean
$receiver: GET_FIELD 'FIELD PROPERTY_DELEGATE name:x$delegate type:kotlin.Lazy<@[EnhancedNullability] kotlin.Boolean> visibility:private [final,static]' type=kotlin.Lazy<@[EnhancedNullability] kotlin.Boolean> origin=null
thisRef: CONST Null type=kotlin.Nothing? value=null
property: PROPERTY_REFERENCE 'public final x: @[EnhancedNullability] kotlin.Boolean' field=null getter='public final fun <get-x> (): @[EnhancedNullability] kotlin.Boolean declared in <root>' setter=null type=kotlin.reflect.KProperty0<@[EnhancedNullability] kotlin.Boolean> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public final fun println (message: kotlin.Boolean): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null
message: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_NOTNULL typeOperand=kotlin.Boolean
CALL 'public final fun <get-x> (): @[EnhancedNullability] kotlin.Boolean declared in <root>' type=@[EnhancedNullability] kotlin.Boolean origin=GET_PROPERTY
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM_IR
// SEPARATE_SIGNATURE_DUMP_FOR_K2
// ISSUE: KT-53886
// WITH_STDLIB
// FILE: A.java
import org.jetbrains.annotations.*;
public class A {
@Nullable
public <T> T get(@NotNull Key<T> key) {
return null;
}
public static class Key<T> {}
}
// FILE: test.kt
val key = A.Key<Boolean>()
val x by lazy {
A().get(key) ?: false
}
fun main() {
println(x)
}
@@ -0,0 +1,22 @@
val key: Key<Boolean>
field = Key<@FlexibleNullability Boolean?>()
get
val x: @EnhancedNullability Boolean /* by */
field = lazy<@EnhancedNullability Boolean>(initializer = local fun <anonymous>(): @EnhancedNullability Boolean {
return { // BLOCK
val tmp_0: @EnhancedNullability Boolean? = A().get<@FlexibleNullability Boolean?>(key = <get-key>())
when {
EQEQ(arg0 = tmp_0, arg1 = null) -> false
else -> tmp_0
}
}
}
)
get(): @EnhancedNullability Boolean {
return #x$delegate.getValue<@EnhancedNullability Boolean>(thisRef = null, property = ::x)
}
fun main() {
println(message = <get-x>() /*!! Boolean */)
}
@@ -0,0 +1,31 @@
// CHECK:
// Mangled name: {}key
// Public signature: /key|1144547298251177939[0]
// Public signature debug description: {}key
val key: Key<Boolean>
// CHECK JVM_IR:
// Mangled name: #<get-key>(){}A.Key<kotlin.Boolean>
// Public signature: /key.<get-key>|-6107443460337397211[0]
// Public signature debug description: <get-key>(){}A.Key<kotlin.Boolean>
get
// CHECK:
// Mangled name: {}x
// Public signature: /x|-8060530855978347579[0]
// Public signature debug description: {}x
val x: @EnhancedNullability Boolean /* by */
// CHECK JVM_IR:
// Mangled name: #<get-x>(){}kotlin.Boolean{EnhancedNullability}
// Public signature: /x.<get-x>|-384063749268193272[0]
// Public signature debug description: <get-x>(){}kotlin.Boolean{EnhancedNullability}
get(): @EnhancedNullability Boolean
// CHECK JVM_IR:
// Mangled name: #main(){}
// Mangled name for the signature by IR: main(){}
// Mangled name for the signature by Frontend: main(){}%test.kt
// Public signature by IR: /main|-4284757841571462650[0]
// Public signature by IR debug description: main(){}
// Public signature by Frontend: /main|-2141841464851950582[0]
// Public signature by Frontend debug description: main(){}%test.kt
fun main(): Unit