FIR: Respect nullability when substituting stub types

This commit is contained in:
Simon Ogorodnik
2021-11-16 16:22:47 +03:00
committed by teamcity
parent 40a2837b4c
commit 52145e0623
6 changed files with 71 additions and 1 deletions
@@ -4973,6 +4973,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/nullableTypeDelegate.kt");
}
@Test
@TestMetadata("propertyWithFunctionalType.kt")
public void testPropertyWithFunctionalType() throws Exception {
@@ -0,0 +1,32 @@
FILE: nullableTypeDelegate.kt
public abstract interface ReadWriteProperty<R, T> : R|kotlin/Any| {
public abstract operator fun getValue(thisRef: R|R|, prop: R|kotlin/Any|): R|T|
public abstract operator fun setValue(thisRef: R|R|, prop: R|kotlin/Any|, value: R|T|): R|kotlin/Unit|
}
public abstract interface Delegate<R, T> : R|ReadWriteProperty<R, T>| {
}
public abstract interface DatabaseEntity : R|kotlin/Any| {
}
public final fun <Self : R|DatabaseEntity|, Target : R|DatabaseEntity|> R|Self|.directed(clazz: R|java/lang/Class<Target>|): R|Delegate<Self, Target?>| {
^directed Null(null)!!
}
public final class MyClassSome : R|DatabaseEntity| {
public constructor(): R|MyClassSome| {
super<R|kotlin/Any|>()
}
public final var other: R|MyClassSome?|by this@R|/MyClassSome|.R|/directed|<R|MyClassSome|, R|MyClassSome|>(<getClass>(Q|MyClassSome|).R|kotlin/jvm/java|<R|MyClassSome|>)
public get(): R|MyClassSome?| {
^ this@R|/MyClassSome|.D|/MyClassSome.other|.R|SubstitutionOverride</Delegate.getValue: R|Stub (builder inference): TypeVariable(_Target)?|>|(this@R|/MyClassSome|, ::R|/MyClassSome.other|)
}
public set(<set-?>: R|MyClassSome?|): R|kotlin/Unit| {
this@R|/MyClassSome|.D|/MyClassSome.other|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/MyClassSome|, ::R|/MyClassSome.other|, R|<local>/other|)
}
public final fun set(link: R|MyClassSome?|): R|kotlin/Unit| {
this@R|/MyClassSome|.R|/MyClassSome.other| = R|<local>/link|
}
}
@@ -0,0 +1,20 @@
interface ReadWriteProperty<R, T> {
operator fun getValue(thisRef: R, prop: Any): T
operator fun setValue(thisRef: R, prop: Any, value: T)
}
interface Delegate<R, T> : ReadWriteProperty<R, T>
interface DatabaseEntity
fun <Self : DatabaseEntity, Target : DatabaseEntity> Self.directed(clazz: Class<Target>):
Delegate<Self, Target?> = null!!
class MyClassSome : DatabaseEntity {
var other by directed(MyClassSome::class.java)
fun set(link: MyClassSome?) {
other = link
}
}
@@ -4973,6 +4973,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/nullableTypeDelegate.kt");
}
@Test
@TestMetadata("propertyWithFunctionalType.kt")
public void testPropertyWithFunctionalType() throws Exception {
@@ -4973,6 +4973,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/nullableTypeDelegate.kt");
}
@Test
@TestMetadata("propertyWithFunctionalType.kt")
public void testPropertyWithFunctionalType() throws Exception {
@@ -116,7 +116,7 @@ class FirDelegatedPropertyInferenceSession(
return object : AbstractConeSubstitutor(typeContext) {
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeStubType) return null
return bindings[type.constructor]
return bindings[type.constructor].updateNullabilityIfNeeded(type)
}
}
}