K2: implement FirLateinitIntrinsicApplicabilityChecker ^KT-55495 Fixed

This commit is contained in:
Kirill Rakhman
2023-01-03 16:52:18 +01:00
committed by Space Team
parent cfe8bc682c
commit 721a37f7e7
19 changed files with 199 additions and 208 deletions
@@ -51,15 +51,15 @@ open class Foo : Base {
fun onLiteral() {
val p = this::x
p.isInitialized
p.<!LATEINIT_INTRINSIC_CALL_ON_NON_LITERAL!>isInitialized<!>
}
fun onNonLateinit() {
this::nonLateInit.isInitialized
this::nonLateInit.<!LATEINIT_INTRINSIC_CALL_ON_NON_LATEINIT!>isInitialized<!>
}
inline fun inlineFun() {
this::x.isInitialized
this::x.<!LATEINIT_INTRINSIC_CALL_IN_INLINE_FUNCTION!>isInitialized<!>
object {
val z = this@Foo::x.isInitialized
@@ -78,22 +78,22 @@ open class Foo : Base {
}
fun onNonAccessible() {
Foo()::x.isInitialized
Foo()::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
fun onNonLateinit() {
Foo()::nonLateInit.isInitialized
Foo()::nonLateInit.<!LATEINIT_INTRINSIC_CALL_ON_NON_LATEINIT!>isInitialized<!>
}
object Unrelated {
fun onNonAccessible() {
Foo()::x.isInitialized
Foo()::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
class FooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
this::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
@@ -101,6 +101,6 @@ class FooImpl : Foo() {
class OtherFooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
this::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
@@ -1,106 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// !LANGUAGE: -NativeJsProhibitLateinitIsInitalizedIntrinsicWithoutPrivateAccess
// FILE: stdlibInternal.kt
package kotlin.internal
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.BINARY)
internal annotation class AccessibleLateinitPropertyLiteral
// FILE: stdlib.kt
package kotlin
import kotlin.internal.AccessibleLateinitPropertyLiteral
import kotlin.reflect.KProperty0
inline val @receiver:AccessibleLateinitPropertyLiteral KProperty0<*>.isInitialized: Boolean
get() = true
// FILE: test.kt
interface Base {
var x: String
}
open class Foo : Base {
override lateinit var x: String
private lateinit var y: String
var nonLateInit: Int = 1
fun ok() {
val b: Boolean = this::x.isInitialized
val otherInstance = Foo()
otherInstance::x.isInitialized
(this::x).isInitialized
(@Suppress("ALL") (this::x)).isInitialized
object {
fun local() {
class Local {
val xx = this@Foo::x.isInitialized
val yy = this@Foo::y.isInitialized
}
}
}
}
fun onLiteral() {
val p = this::x
p.isInitialized
}
fun onNonLateinit() {
this::nonLateInit.isInitialized
}
inline fun inlineFun() {
this::x.isInitialized
object {
val z = this@Foo::x.isInitialized
}
}
inner class InnerSubclass : Foo() {
fun innerOk() {
// This is access to Foo.x declared lexically above
this@Foo::x.isInitialized
// This is access to InnerSubclass.x which is inherited from Foo.x
this::x.isInitialized
}
}
}
fun onNonAccessible() {
Foo()::x.isInitialized
}
fun onNonLateinit() {
Foo()::nonLateInit.isInitialized
}
object Unrelated {
fun onNonAccessible() {
Foo()::x.isInitialized
}
}
class FooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
}
}
// FILE: other.kt
class OtherFooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// !LANGUAGE: +NativeJsProhibitLateinitIsInitalizedIntrinsicWithoutPrivateAccess
// FILE: stdlibInternal.kt
@@ -1,87 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// FILE: test.kt
interface Base {
var x: String
}
open class Foo : Base {
override lateinit var x: String
private lateinit var y: String
var nonLateInit: Int = 1
fun ok() {
val b: Boolean = this::x.isInitialized
val otherInstance = Foo()
otherInstance::x.isInitialized
(this::x).isInitialized
(@Suppress("ALL") (this::x)).isInitialized
object {
fun local() {
class Local {
val xx = this@Foo::x.isInitialized
val yy = this@Foo::y.isInitialized
}
}
}
}
fun onLiteral() {
val p = this::x
p.isInitialized
}
fun onNonLateinit() {
this::nonLateInit.isInitialized
}
inline fun inlineFun() {
this::x.isInitialized
object {
val z = this@Foo::x.isInitialized
}
}
inner class InnerSubclass : Foo() {
fun innerOk() {
// This is access to Foo.x declared lexically above
this@Foo::x.isInitialized
// This is access to InnerSubclass.x which is inherited from Foo.x
this::x.isInitialized
}
}
}
fun onNonAccessible() {
Foo()::x.isInitialized
}
fun onNonLateinit() {
Foo()::nonLateInit.isInitialized
}
object Unrelated {
fun onNonAccessible() {
Foo()::x.isInitialized
}
}
class FooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
}
}
// FILE: other.kt
class OtherFooImpl : Foo() {
fun onNonAccessible() {
this::x.isInitialized
}
}
@@ -1,6 +1,9 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// FILE: test.kt
lateinit var topLevel: String
interface Base {
var x: String
}
@@ -12,6 +15,7 @@ open class Foo : Base {
var nonLateInit: Int = 1
fun ok() {
::topLevel.isInitialized
val b: Boolean = this::x.isInitialized
val otherInstance = Foo()
@@ -83,5 +87,6 @@ class FooImpl : Foo() {
class OtherFooImpl : Foo() {
fun onNonAccessible() {
this::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
::topLevel.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
@@ -1,5 +1,6 @@
package
public lateinit var topLevel: kotlin.String
public fun onNonAccessible(): kotlin.Unit
public fun onNonLateinit(): kotlin.Unit
@@ -76,3 +77,4 @@ public object Unrelated {
public final fun onNonAccessible(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}