[FIR] Assume nullable types as good types for ILT approximation
#KT-41982 Fixed
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// ISSUE: KT-41982
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate<R, T> {
|
||||
operator fun getValue(thisRef: R, property: KProperty<*>): T = null!!
|
||||
|
||||
operator fun setValue(thisRef: R, property: KProperty<*>, value: T) {}
|
||||
}
|
||||
|
||||
abstract class DelegateProvider<in Type>
|
||||
|
||||
fun <Type : Base, Base : DelegateProvider<Base>> Type.long(initializer: (() -> Long?)? = null): Delegate<Type, Long> = null!!
|
||||
|
||||
class Test : DelegateProvider<Any>() {
|
||||
var start by long { 0 }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
FILE: kt41982.kt
|
||||
public final class Delegate<R, T> : R|kotlin/Any| {
|
||||
public constructor<R, T>(): R|Delegate<R, T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final operator fun getValue(thisRef: R|R|, property: R|kotlin/reflect/KProperty<*>|): R|T| {
|
||||
^getValue Null(null)!!
|
||||
}
|
||||
|
||||
public final operator fun setValue(thisRef: R|R|, property: R|kotlin/reflect/KProperty<*>|, value: R|T|): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
public abstract class DelegateProvider<in Type> : R|kotlin/Any| {
|
||||
public constructor<in Type>(): R|DelegateProvider<Type>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final fun <Type : R|Base|, Base : R|DelegateProvider<Base>|> R|Type|.long(initializer: R|() -> kotlin/Long?| = Null(null)): R|Delegate<Type, kotlin/Long>| {
|
||||
^long Null(null)!!
|
||||
}
|
||||
public final class Test : R|DelegateProvider<kotlin/Any>| {
|
||||
public constructor(): R|Test| {
|
||||
super<R|DelegateProvider<kotlin/Any>|>()
|
||||
}
|
||||
|
||||
public final var start: R|kotlin/Long|by this@R|/Test|.R|/long|<R|Test?|, R|Test?|>(<L> = long@fun <anonymous>(): R|kotlin/Long?| {
|
||||
^ Long(0)
|
||||
}
|
||||
)
|
||||
public get(): R|kotlin/Long| {
|
||||
^ this@R|/Test|.D|/Test.start|.R|FakeOverride</Delegate.getValue: R|kotlin/Long|>|(this@R|/Test|, ::R|/Test.start|)
|
||||
}
|
||||
public set(<set-?>: R|kotlin/Long|): R|kotlin/Unit| {
|
||||
this@R|/Test|.D|/Test.start|.R|FakeOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/Test|, ::R|/Test.start|, R|<local>/start|)
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+5
@@ -898,6 +898,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41982.kt")
|
||||
public void testKt41982() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/kt41982.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("provideDelegate.kt")
|
||||
public void testProvideDelegate() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/provideDelegate.kt");
|
||||
|
||||
+5
@@ -898,6 +898,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/extensionGetValueWithTypeVariableAsReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41982.kt")
|
||||
public void testKt41982() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/kt41982.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("provideDelegate.kt")
|
||||
public void testProvideDelegate() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/provideDelegate.kt");
|
||||
|
||||
@@ -64,9 +64,11 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
|
||||
}
|
||||
|
||||
override fun getApproximatedType(expectedType: ConeKotlinType?): ConeClassLikeType {
|
||||
val approximatedType = when (val expectedTypeForApproximation = expectedType?.lowerBoundIfFlexible()) {
|
||||
val expectedTypeForApproximation = (expectedType?.lowerBoundIfFlexible() as? ConeClassLikeType)
|
||||
?.withNullability(ConeNullability.NOT_NULL)
|
||||
val approximatedType = when (expectedTypeForApproximation) {
|
||||
null, !in possibleTypes -> possibleTypes.first()
|
||||
else -> expectedTypeForApproximation as ConeClassLikeType
|
||||
else -> expectedTypeForApproximation
|
||||
}
|
||||
return approximatedType.withNullability(nullability)
|
||||
}
|
||||
@@ -155,4 +157,4 @@ private fun ConeClassLikeType.withNullability(nullability: ConeNullability): Con
|
||||
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable)
|
||||
else -> error("sealed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
@@ -20,4 +18,4 @@ fun box(): String {
|
||||
return targets.toList().toString()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: StringHolder.java
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
+2
-2
@@ -63,9 +63,9 @@ FILE fqName:<root> fileName:/primitivesImplicitConversions.kt
|
||||
VAR name:test2 type:kotlin.Long [val]
|
||||
CONST Long type=kotlin.Long value=42
|
||||
VAR name:test3 type:kotlin.Long? [val]
|
||||
CONST Int type=kotlin.Int value=42
|
||||
CONST Long type=kotlin.Long value=42
|
||||
VAR name:test4 type:kotlin.Long? [val]
|
||||
CONST Int type=kotlin.Int value=-1
|
||||
CONST Long type=kotlin.Long value=-1
|
||||
VAR name:test5 type:kotlin.Long? [val]
|
||||
CONST Int type=kotlin.Int value=-1
|
||||
VAR name:test6 type:kotlin.Short? [val]
|
||||
|
||||
Reference in New Issue
Block a user