diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 3c1a7600268..3d15e695320 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index af1dd22d2f2..b3ffe2fc6f2 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -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"); diff --git a/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.fir.txt b/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.fir.txt new file mode 100644 index 00000000000..c3d91da0777 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.fir.txt @@ -0,0 +1,33 @@ +FILE: callOnThisInDelegateExpression.kt + public abstract interface Delegate : R|kotlin/properties/ReadWriteProperty| { + public abstract infix fun resource(factory: R|Factory|): R|Delegate| + + } + public abstract interface Factory : R|kotlin/Any| { + } + public abstract interface Some : R|kotlin/Any| { + } + public final fun R|Self|.delegateOf(clazz: R|java/lang/Class|): R|Delegate| { + ^delegateOf Null(null)!! + } + public abstract class SomeImpl : R|Some| { + public constructor(): R|SomeImpl| { + super() + } + + public abstract val type: R|java/lang/Class| + public get(): R|java/lang/Class| + + public final var bundle: R|R?|by this@R|/SomeImpl|.R|/delegateOf||, R|R|>(this@R|/SomeImpl|.R|/SomeImpl.type|).R|SubstitutionOverride, R?>|>|(this@R|/SomeImpl|.R|/SomeImpl.getFactory||, R|R|>()) + public get(): R|R?| { + ^ this@R|/SomeImpl|.D|/SomeImpl.bundle|.R|SubstitutionOverride|(this@R|/SomeImpl|, ::R|/SomeImpl.bundle|) + } + public set(: R|R?|): R|kotlin/Unit| { + this@R|/SomeImpl|.D|/SomeImpl.bundle|.R|SubstitutionOverride|(this@R|/SomeImpl|, ::R|/SomeImpl.bundle|, R|/bundle|) + } + + public final fun |, T : R|Some|> getFactory(): R|Factory| { + ^getFactory Null(null)!! + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt b/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt new file mode 100644 index 00000000000..b46173764d0 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/delegates/callOnThisInDelegateExpression.kt @@ -0,0 +1,21 @@ +// WITH_STDLIB +// ISSUE: KT-57288 +import kotlin.properties.ReadWriteProperty + +interface Delegate : ReadWriteProperty { + infix fun resource(factory: Factory): Delegate +} + +interface Factory + +interface Some + +fun Self.delegateOf(clazz: Class): Delegate = null!! + +abstract class SomeImpl : Some { + abstract val type: Class + + var bundle by delegateOf(type) resource getFactory() + + fun , T : Some> getFactory(): Factory = null!! +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java index 1cc9d73cc1b..761f81a1b34 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java index bfd5b1b36be..57d7d800383 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java @@ -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 { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index ff224401394..fe67a1cea32 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -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, ) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 95eb14b268d..d0862064509 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -227,7 +227,6 @@ open class RawFirBuilder( ownerRegularClassTypeParametersCount: Int? ): FirProperty = property.toFirProperty( ownerRegularOrAnonymousObjectSymbol, - ownerRegularClassTypeParametersCount, context ) @@ -1719,7 +1718,6 @@ open class RawFirBuilder( private fun KtProperty.toFirProperty( ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?, - ownerRegularClassTypeParametersCount: Int?, context: Context ): 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 ) } diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 2947cd0ae15..4ad1b4f7c3a 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -299,7 +299,6 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( delegateBuilder: FirWrappedDelegateExpressionBuilder?, moduleData: FirModuleData, ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?, - ownerRegularClassTypeParametersCount: Int?, context: Context, isExtension: Boolean, ) { @@ -339,8 +338,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( boundSymbol = ownerRegularOrAnonymousObjectSymbol } typeRef = buildResolvedTypeRef { - val typeParameterNumber = ownerRegularClassTypeParametersCount ?: 0 - type = ownerRegularOrAnonymousObjectSymbol.constructStarProjectedType(typeParameterNumber) + type = context.dispatchReceiverTypesStack.last() } } else -> buildConstExpression(null, ConstantValueKind.Null, null) diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt index 4033fc08d30..84e873f6bc8 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt @@ -279,8 +279,7 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt RETURN type=kotlin.Nothing from='private final fun (): T of . declared in .additionalText$delegate.' CALL 'public open fun getValue (t: .Value., .CR.>>, p: kotlin.reflect.KProperty<*>): T of . [operator] declared in .additionalText$delegate..deepO$delegate.' type=T of . origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepO$delegate type:.additionalText$delegate..deepO$delegate..> visibility:private [final]' type=.additionalText$delegate..deepO$delegate..> origin=null - receiver: TYPE_OP type=.additionalText$delegate. origin=IMPLICIT_CAST typeOperand=.additionalText$delegate. - GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null + receiver: GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null t: GET_VAR ': .Value., .CR.>> declared in .additionalText$delegate..' type=.Value., .CR.>> origin=null p: PROPERTY_REFERENCE 'private final deepO: T of . [delegated,val]' field=null getter='private final fun (): T of . declared in .additionalText$delegate.' setter=null type=kotlin.reflect.KProperty2<.Value., .CR.>>, *, T of .> origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY name:deepK visibility:private modality:FINAL [delegated,val] @@ -326,8 +325,7 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt RETURN type=kotlin.Nothing from='private final fun (): T of . declared in .additionalText$delegate.' CALL 'public open fun getValue (t: .Value., .CR.>>, p: kotlin.reflect.KProperty<*>): T of . [operator] declared in .additionalText$delegate..deepK$delegate.' type=T of . origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepK$delegate type:.additionalText$delegate..deepK$delegate..> visibility:private [final]' type=.additionalText$delegate..deepK$delegate..> origin=null - receiver: TYPE_OP type=.additionalText$delegate. origin=IMPLICIT_CAST typeOperand=.additionalText$delegate. - GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null + receiver: GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null t: GET_VAR ': .Value., .CR.>> declared in .additionalText$delegate..' type=.Value., .CR.>> origin=null p: PROPERTY_REFERENCE 'private final deepK: T of . [delegated,val]' field=null getter='private final fun (): T of . declared in .additionalText$delegate.' setter=null type=kotlin.reflect.KProperty2<.Value., .CR.>>, *, T of .> origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN name:getValue visibility:public modality:OPEN <> ($this:.additionalText$delegate..>, t:.Value., .CR.>>, p:kotlin.reflect.KProperty<*>) returnType:.P., T of .> [operator] diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt index 55bc746ec4f..0a8e4f04b4c 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt @@ -108,7 +108,7 @@ val Value>.additionalText: P /* by */ () } private get(): T { - return /*as */.#deepO$delegate.getValue(t = , p = ::deepO) + return .#deepO$delegate.getValue(t = , p = ::deepO) } private val Value>.deepK: T /* by */ @@ -129,7 +129,7 @@ val Value>.additionalText: P /* by */ () } private get(): T { - return /*as */.#deepK$delegate.getValue(t = , p = ::deepK) + return .#deepK$delegate.getValue(t = , p = ::deepK) } override operator fun getValue(t: Value>, p: KProperty<*>): P {