[FIR] Create this reference for getValue calls in delegates with proper type
^KT-57288 Fixed
This commit is contained in:
committed by
Space Team
parent
823c60a7dc
commit
16872f7a74
+6
@@ -1621,6 +1621,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callOnThisInDelegateExpression.kt")
|
||||
public void testCallOnThisInDelegateExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateInference.kt")
|
||||
public void testDelegateInference() throws Exception {
|
||||
|
||||
+5
@@ -1414,6 +1414,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callOnThisInDelegateExpression.kt")
|
||||
public void testCallOnThisInDelegateExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateInference.kt")
|
||||
public void testDelegateInference() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/delegateInference.kt");
|
||||
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
FILE: callOnThisInDelegateExpression.kt
|
||||
public abstract interface Delegate<R, T> : R|kotlin/properties/ReadWriteProperty<R, T>| {
|
||||
public abstract infix fun resource(factory: R|Factory<R, T>|): R|Delegate<R, T>|
|
||||
|
||||
}
|
||||
public abstract interface Factory<Source, Target> : R|kotlin/Any| {
|
||||
}
|
||||
public abstract interface Some : R|kotlin/Any| {
|
||||
}
|
||||
public final fun <Self : R|Some|, Target : R|Some|> R|Self|.delegateOf(clazz: R|java/lang/Class<Target>|): R|Delegate<Self, Target?>| {
|
||||
^delegateOf Null(null)!!
|
||||
}
|
||||
public abstract class SomeImpl<R : R|Some|> : R|Some| {
|
||||
public constructor<R : R|Some|>(): R|SomeImpl<R>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public abstract val type: R|java/lang/Class<R>|
|
||||
public get(): R|java/lang/Class<R>|
|
||||
|
||||
public final var bundle: R|R?|by this@R|/SomeImpl|.R|/delegateOf|<R|SomeImpl<R>|, R|R|>(this@R|/SomeImpl|.R|/SomeImpl.type|).R|SubstitutionOverride</Delegate.resource: R|Delegate<SomeImpl<R>, R?>|>|(this@R|/SomeImpl|.R|/SomeImpl.getFactory|<R|SomeImpl<R>|, R|R|>())
|
||||
public get(): R|R?| {
|
||||
^ this@R|/SomeImpl|.D|/SomeImpl.bundle|.R|SubstitutionOverride</Delegate.getValue: R|R?|>|(this@R|/SomeImpl|, ::R|/SomeImpl.bundle|)
|
||||
}
|
||||
public set(<set-?>: R|R?|): R|kotlin/Unit| {
|
||||
this@R|/SomeImpl|.D|/SomeImpl.bundle|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/SomeImpl|, ::R|/SomeImpl.bundle|, R|<local>/bundle|)
|
||||
}
|
||||
|
||||
public final fun <M : R|SomeImpl<T>|, T : R|Some|> getFactory(): R|Factory<M, T?>| {
|
||||
^getFactory Null(null)!!
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-57288
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
interface Delegate<R, T> : ReadWriteProperty<R, T> {
|
||||
infix fun resource(factory: Factory<R, T>): Delegate<R, T>
|
||||
}
|
||||
|
||||
interface Factory<Source, Target>
|
||||
|
||||
interface Some
|
||||
|
||||
fun <Self : Some, Target : Some> Self.delegateOf(clazz: Class<Target>): Delegate<Self, Target?> = null!!
|
||||
|
||||
abstract class SomeImpl<R : Some> : Some {
|
||||
abstract val type: Class<R>
|
||||
|
||||
var bundle by delegateOf(type) resource getFactory()
|
||||
|
||||
fun <M : SomeImpl<T>, T : Some> getFactory(): Factory<M, T?> = null!!
|
||||
}
|
||||
+6
@@ -1621,6 +1621,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callOnThisInDelegateExpression.kt")
|
||||
public void testCallOnThisInDelegateExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateInference.kt")
|
||||
public void testDelegateInference() throws Exception {
|
||||
|
||||
+6
@@ -1621,6 +1621,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callOnThisInDelegateExpression.kt")
|
||||
public void testCallOnThisInDelegateExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateInference.kt")
|
||||
public void testDelegateInference() throws Exception {
|
||||
|
||||
+2
-4
@@ -1235,9 +1235,8 @@ class DeclarationsConverter(
|
||||
delegateBuilder,
|
||||
baseModuleData,
|
||||
classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol,
|
||||
classWrapper?.classBuilder?.ownerRegularClassTypeParametersCount,
|
||||
isExtension = false,
|
||||
context = context
|
||||
context = context,
|
||||
isExtension = false
|
||||
)
|
||||
} else {
|
||||
this.isLocal = false
|
||||
@@ -1309,7 +1308,6 @@ class DeclarationsConverter(
|
||||
delegateBuilder,
|
||||
baseModuleData,
|
||||
classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol,
|
||||
classWrapper?.classBuilder?.ownerRegularClassTypeParametersCount,
|
||||
context,
|
||||
isExtension = receiverType != null,
|
||||
)
|
||||
|
||||
@@ -227,7 +227,6 @@ open class RawFirBuilder(
|
||||
ownerRegularClassTypeParametersCount: Int?
|
||||
): FirProperty = property.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol,
|
||||
ownerRegularClassTypeParametersCount,
|
||||
context
|
||||
)
|
||||
|
||||
@@ -1719,7 +1718,6 @@ open class RawFirBuilder(
|
||||
|
||||
private fun <T> KtProperty.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
context: Context<T>
|
||||
): FirProperty {
|
||||
val propertyType = typeReference.toFirOrImplicitType()
|
||||
@@ -1773,9 +1771,8 @@ open class RawFirBuilder(
|
||||
delegateBuilder,
|
||||
baseModuleData,
|
||||
ownerRegularOrAnonymousObjectSymbol = null,
|
||||
ownerRegularClassTypeParametersCount = null,
|
||||
isExtension = false,
|
||||
context = context,
|
||||
isExtension = false,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -1835,7 +1832,6 @@ open class RawFirBuilder(
|
||||
delegateBuilder,
|
||||
baseModuleData,
|
||||
ownerRegularOrAnonymousObjectSymbol,
|
||||
ownerRegularClassTypeParametersCount,
|
||||
context,
|
||||
isExtension = receiverTypeReference != null,
|
||||
)
|
||||
@@ -1868,7 +1864,6 @@ open class RawFirBuilder(
|
||||
override fun visitProperty(property: KtProperty, data: Unit): FirElement {
|
||||
return property.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol = null,
|
||||
ownerRegularClassTypeParametersCount = null,
|
||||
context = context
|
||||
)
|
||||
}
|
||||
|
||||
+1
-3
@@ -299,7 +299,6 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
delegateBuilder: FirWrappedDelegateExpressionBuilder?,
|
||||
moduleData: FirModuleData,
|
||||
ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
context: Context<T>,
|
||||
isExtension: Boolean,
|
||||
) {
|
||||
@@ -339,8 +338,7 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
boundSymbol = ownerRegularOrAnonymousObjectSymbol
|
||||
}
|
||||
typeRef = buildResolvedTypeRef {
|
||||
val typeParameterNumber = ownerRegularClassTypeParametersCount ?: 0
|
||||
type = ownerRegularOrAnonymousObjectSymbol.constructStarProjectedType(typeParameterNumber)
|
||||
type = context.dispatchReceiverTypesStack.last()
|
||||
}
|
||||
}
|
||||
else -> buildConstExpression(null, ConstantValueKind.Null, null)
|
||||
|
||||
@@ -279,8 +279,7 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
|
||||
RETURN type=kotlin.Nothing from='private final fun <get-deepO> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>'
|
||||
CALL 'public open fun getValue (t: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, p: kotlin.reflect.KProperty<*>): T of <root>.<get-additionalText> [operator] declared in <root>.additionalText$delegate.<no name provided>.deepO$delegate.<no name provided>' type=T of <root>.<get-additionalText> origin=null
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepO$delegate type:<root>.additionalText$delegate.<no name provided>.deepO$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final]' type=<root>.additionalText$delegate.<no name provided>.deepO$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
receiver: TYPE_OP type=<root>.additionalText$delegate.<no name provided> origin=IMPLICIT_CAST typeOperand=<root>.additionalText$delegate.<no name provided>
|
||||
GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepO>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
receiver: GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepO>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepO>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null
|
||||
p: PROPERTY_REFERENCE 'private final deepO: T of <root>.<get-additionalText> [delegated,val]' field=null getter='private final fun <get-deepO> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>' setter=null type=kotlin.reflect.KProperty2<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, *, T of <root>.<get-additionalText>> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
PROPERTY name:deepK visibility:private modality:FINAL [delegated,val]
|
||||
@@ -326,8 +325,7 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
|
||||
RETURN type=kotlin.Nothing from='private final fun <get-deepK> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>'
|
||||
CALL 'public open fun getValue (t: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, p: kotlin.reflect.KProperty<*>): T of <root>.<get-additionalText> [operator] declared in <root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided>' type=T of <root>.<get-additionalText> origin=null
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepK$delegate type:<root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final]' type=<root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
receiver: TYPE_OP type=<root>.additionalText$delegate.<no name provided> origin=IMPLICIT_CAST typeOperand=<root>.additionalText$delegate.<no name provided>
|
||||
GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepK>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
receiver: GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepK>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
|
||||
t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepK>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null
|
||||
p: PROPERTY_REFERENCE 'private final deepK: T of <root>.<get-additionalText> [delegated,val]' field=null getter='private final fun <get-deepK> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>' setter=null type=kotlin.reflect.KProperty2<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, *, T of <root>.<get-additionalText>> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
FUN name:getValue visibility:public modality:OPEN <> ($this:<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>>, t:<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, p:kotlin.reflect.KProperty<*>) returnType:<root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> [operator]
|
||||
|
||||
@@ -108,7 +108,7 @@ val <T : Any?> Value<T, CR<T>>.additionalText: P<T, T> /* by */
|
||||
<no name provided>()
|
||||
}
|
||||
private get(): T {
|
||||
return <this> /*as <no name provided> */.#deepO$delegate.getValue(t = <this>, p = <no name provided>::deepO)
|
||||
return <this>.#deepO$delegate.getValue(t = <this>, p = <no name provided>::deepO)
|
||||
}
|
||||
|
||||
private val Value<T, CR<T>>.deepK: T /* by */
|
||||
@@ -129,7 +129,7 @@ val <T : Any?> Value<T, CR<T>>.additionalText: P<T, T> /* by */
|
||||
<no name provided>()
|
||||
}
|
||||
private get(): T {
|
||||
return <this> /*as <no name provided> */.#deepK$delegate.getValue(t = <this>, p = <no name provided>::deepK)
|
||||
return <this>.#deepK$delegate.getValue(t = <this>, p = <no name provided>::deepK)
|
||||
}
|
||||
|
||||
override operator fun getValue(t: Value<T, CR<T>>, p: KProperty<*>): P<T, T> {
|
||||
|
||||
Reference in New Issue
Block a user