diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index c917bcbe05c..19e1ae1bcbc 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -14393,6 +14393,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/builderInference/labaledCall.kt"); } + @Test + @TestMetadata("propertySubstitution.kt") + public void testPropertySubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index a30f03d7190..b384425632c 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -14393,6 +14393,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/builderInference/labaledCall.kt"); } + @Test + @TestMetadata("propertySubstitution.kt") + public void testPropertySubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index a6fa380bd3c..36b2e79f544 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -14393,6 +14393,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/builderInference/labaledCall.kt"); } + @Test + @TestMetadata("propertySubstitution.kt") + public void testPropertySubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index af7a67f21b2..4cbf72f3e0b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -3012,6 +3012,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt"); } + @Test + @TestMetadata("dontLeaveStubTypesInSetter.kt") + public void testDontLeaveStubTypesInSetter() throws Exception { + runTest("compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt"); + } + @Test @TestMetadata("genericDelegatedDeepProperty.kt") public void testGenericDelegatedDeepProperty() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java index 28c52f38b9c..24c4810ae97 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java @@ -3012,6 +3012,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex runTest("compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt"); } + @Test + @TestMetadata("dontLeaveStubTypesInSetter.kt") + public void testDontLeaveStubTypesInSetter() throws Exception { + runTest("compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt"); + } + @Test @TestMetadata("genericDelegatedDeepProperty.kt") public void testGenericDelegatedDeepProperty() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt b/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt new file mode 100644 index 00000000000..57a8e5e80ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt @@ -0,0 +1,45 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +interface FirJavaClass2 { + val superTypeRefs: MutableList +} + +interface ConeKotlinType2 + +class ClassId2 + +val ConeKotlinType2.classId: ClassId2? get() = null + +interface FirSignatureEnhancement2 { + fun enhanceSuperType(type: FirTypeRef2): FirTypeRef2 = TODO() +} + +interface FirTypeRef2 + +val FirTypeRef2.coneType: ConeKotlinType2 get() = TODO() + +private fun FirJavaClass2.getPurelyImplementedSupertype(): ConeKotlinType2? = null + +inline fun buildResolvedTypeRef2(init: FirResolvedTypeRefBuilder2.() -> Unit): FirResolvedTypeRef2 = TODO() + +interface FirResolvedTypeRef2 : FirTypeRef2 + +class FirResolvedTypeRefBuilder2 { + lateinit var type: ConeKotlinType2 +} + +fun foo(firJavaClass: FirJavaClass2, enhancement: FirSignatureEnhancement2) { + val enhancedSuperTypes = buildList { + val purelyImplementedSupertype = firJavaClass.getPurelyImplementedSupertype() + val purelyImplementedSupertypeClassId = purelyImplementedSupertype?.classId + firJavaClass.superTypeRefs.mapNotNullTo(this) { superType -> + enhancement.enhanceSuperType(superType).takeUnless { + purelyImplementedSupertypeClassId != null && it.coneType.classId == purelyImplementedSupertypeClassId + } + } + purelyImplementedSupertype?.let { + add(buildResolvedTypeRef2 { type = it }) + } + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.txt b/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.txt new file mode 100644 index 00000000000..4f5b2a86e91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.txt @@ -0,0 +1,54 @@ +package + +public val ConeKotlinType2.classId: ClassId2? +public val FirTypeRef2.coneType: ConeKotlinType2 +public inline fun buildResolvedTypeRef2(/*0*/ init: FirResolvedTypeRefBuilder2.() -> kotlin.Unit): FirResolvedTypeRef2 +public fun foo(/*0*/ firJavaClass: FirJavaClass2, /*1*/ enhancement: FirSignatureEnhancement2): kotlin.Unit +private fun FirJavaClass2.getPurelyImplementedSupertype(): ConeKotlinType2? + +public final class ClassId2 { + public constructor ClassId2() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ConeKotlinType2 { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface FirJavaClass2 { + public abstract val superTypeRefs: kotlin.collections.MutableList + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface FirResolvedTypeRef2 : FirTypeRef2 { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class FirResolvedTypeRefBuilder2 { + public constructor FirResolvedTypeRefBuilder2() + public final lateinit var type: ConeKotlinType2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface FirSignatureEnhancement2 { + public open fun enhanceSuperType(/*0*/ type: FirTypeRef2): FirTypeRef2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface FirTypeRef2 { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.ir.txt b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.ir.txt new file mode 100644 index 00000000000..32992602d50 --- /dev/null +++ b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.ir.txt @@ -0,0 +1,67 @@ +FILE fqName: fileName:/dontLeaveStubTypesInSetter.kt + CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.Foo> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + CONSTRUCTOR visibility:public <> (x:T of .Foo) returnType:.Foo.Foo> [primary] + VALUE_PARAMETER name:x index:0 type:T of .Foo + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:x visibility:public modality:FINAL [var] + FIELD PROPERTY_BACKING_FIELD name:x type:T of .Foo visibility:private + EXPRESSION_BODY + GET_VAR 'x: T of .Foo declared in .Foo.' type=T of .Foo origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Foo.Foo>) returnType:T of .Foo + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.Foo.Foo> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): T of .Foo declared in .Foo' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of .Foo visibility:private' type=T of .Foo origin=null + receiver: GET_VAR ': .Foo.Foo> declared in .Foo.' type=.Foo.Foo> origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Foo.Foo>, :T of .Foo) returnType:kotlin.Unit + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.Foo.Foo> + VALUE_PARAMETER name: index:0 type:T of .Foo + BLOCK_BODY + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of .Foo visibility:private' type=kotlin.Unit origin=null + receiver: GET_VAR ': .Foo.Foo> declared in .Foo.' type=.Foo.Foo> origin=null + value: GET_VAR ': T of .Foo declared in .Foo.' type=T of .Foo origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:foo visibility:public modality:FINAL (x:kotlin.collections.MutableList.foo>) returnType:.Foo.foo> + TYPE_PARAMETER name:K index:0 variance: superTypes:[kotlin.Any?] reified:false + VALUE_PARAMETER name:x index:0 type:kotlin.collections.MutableList.foo> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (x: kotlin.collections.MutableList.foo>): .Foo.foo> declared in ' + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin.StandardKt' type=kotlin.Nothing origin=null + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:x type:kotlin.collections.List [val] + CALL 'public final fun buildList (builderAction: @[ExtensionFunctionType] kotlin.Function1, kotlin.Unit>): kotlin.collections.List [inline] declared in kotlin.collections.CollectionsKt' type=kotlin.collections.List origin=null + : kotlin.String + builderAction: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.collections.MutableList) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$buildList type:kotlin.collections.MutableList + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun add (element: E of kotlin.collections.MutableList): kotlin.Boolean declared in kotlin.collections.MutableList' type=kotlin.Boolean origin=null + $this: GET_VAR '$this$buildList: kotlin.collections.MutableList declared in .main.' type=kotlin.collections.MutableList origin=null + element: CONST String type=kotlin.String value="" + VAR name:foo type:.Foo [val] + CALL 'public final fun foo (x: kotlin.collections.MutableList.foo>): .Foo.foo> declared in ' type=.Foo origin=null + : kotlin.String + x: GET_VAR '$this$buildList: kotlin.collections.MutableList declared in .main.' type=kotlin.collections.MutableList origin=null + CALL 'public final fun (: T of .Foo): kotlin.Unit declared in .Foo' type=kotlin.Unit origin=EQ + $this: GET_VAR 'val foo: .Foo [val] declared in .main.' type=.Foo origin=null + : CONST String type=kotlin.String value="" diff --git a/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt new file mode 100644 index 00000000000..7b2d5769d77 --- /dev/null +++ b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +class Foo(var x: T) + +fun foo(x: MutableList): Foo = TODO() + +fun main() { + val x = buildList { + add("") + val foo = foo(this) + foo.x = "" + } +} diff --git a/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt.txt b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt.txt new file mode 100644 index 00000000000..3ae57d294e2 --- /dev/null +++ b/compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt.txt @@ -0,0 +1,26 @@ +class Foo { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + var x: T + field = x + get + set + +} + +fun foo(x: MutableList): Foo { + return TODO() +} + +fun main() { + val x: List = buildList(builderAction = local fun MutableList.() { + $this$buildList.add(element = "") /*~> Unit */ + val foo: Foo = foo(x = $this$buildList) + foo.( = "") + } +) +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 7aec814732f..dd9659a28a5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -14399,6 +14399,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/labaledCall.kt"); } + @Test + @TestMetadata("propertySubstitution.kt") + public void testPropertySubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/propertySubstitution.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 90007938da8..045500b87eb 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -3012,6 +3012,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt"); } + @Test + @TestMetadata("dontLeaveStubTypesInSetter.kt") + public void testDontLeaveStubTypesInSetter() throws Exception { + runTest("compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt"); + } + @Test @TestMetadata("genericDelegatedDeepProperty.kt") public void testGenericDelegatedDeepProperty() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java index 8ed0f492bb9..bd0635f5c82 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java @@ -2182,6 +2182,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt"); } + @TestMetadata("dontLeaveStubTypesInSetter.kt") + public void testDontLeaveStubTypesInSetter() throws Exception { + runTest("compiler/testData/ir/irText/types/dontLeaveStubTypesInSetter.kt"); + } + @TestMetadata("genericDelegatedDeepProperty.kt") public void testGenericDelegatedDeepProperty() throws Exception { runTest("compiler/testData/ir/irText/types/genericDelegatedDeepProperty.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java index 02b5e9d790b..0663b59e73a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java @@ -119,7 +119,7 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript @NotNull @Override public FunctionDescriptor substitute(@NotNull TypeSubstitutor substitutor) { - throw new UnsupportedOperationException(); // TODO + return this; // no substitution since we work with originals of accessors in the backend anyway } @NotNull