From d8a20f197504db9bdd723f591a2af258309d66b5 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 12 Jun 2023 17:52:30 +0200 Subject: [PATCH] K2: don't generate Java overridden synthetics for Kotlin get/sets #KT-59038 Fixed --- ...cCompilerTestFirTestdataTestGenerated.java | 18 ++++ ...osticCompilerFirTestDataTestGenerated.java | 18 ++++ ...ricGetterForJavaOverriddenProperty.fir.txt | 20 +++++ .../genericGetterForJavaOverriddenProperty.kt | 21 +++++ ...icGetterForJavaOverriddenProperty2.fir.txt | 20 +++++ ...genericGetterForJavaOverriddenProperty2.kt | 21 +++++ .../genericGetterForSyntheticProperty.fir.txt | 7 ++ .../j+k/genericGetterForSyntheticProperty.kt | 18 ++++ .../FirLightTreeDiagnosticsTestGenerated.java | 18 ++++ .../FirPsiDiagnosticTestGenerated.java | 18 ++++ ...LightTreeBlackBoxCodegenTestGenerated.java | 6 ++ .../FirPsiBlackBoxCodegenTestGenerated.java | 6 ++ .../FirLightTreeJvmIrTextTestGenerated.java | 6 ++ .../ir/FirPsiJvmIrTextTestGenerated.java | 6 ++ .../scopes/JavaClassUseSiteMemberScope.kt | 11 ++- .../fir/typeParameterInClashingAccessor.kt | 37 ++++++++ .../TypeParameterInClashingAccessor.ir.txt | 85 +++++++++++++++++++ .../TypeParameterInClashingAccessor.kt | 22 +++++ .../TypeParameterInClashingAccessor.kt.txt | 34 ++++++++ ...TypeParameterInClashingAccessor.sig.kt.txt | 52 ++++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++ ...kBoxCodegenWithIrInlinerTestGenerated.java | 6 ++ .../ir/ClassicJvmIrTextTestGenerated.java | 6 ++ 23 files changed, 459 insertions(+), 3 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt create mode 100644 compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt create mode 100644 compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.ir.txt create mode 100644 compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt create mode 100644 compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt.txt create mode 100644 compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.sig.kt.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java index 806e87a335a..9b1f3825aef 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java @@ -6493,6 +6493,24 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.kt"); } + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty.kt") + public void testGenericGetterForJavaOverriddenProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt"); + } + + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty2.kt") + public void testGenericGetterForJavaOverriddenProperty2() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt"); + } + + @Test + @TestMetadata("genericGetterForSyntheticProperty.kt") + public void testGenericGetterForSyntheticProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt"); + } + @Test @TestMetadata("IntersectionTypesProblem.kt") public void testIntersectionTypesProblem() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java index f370eef0a9c..ef80433a914 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java @@ -6493,6 +6493,24 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.kt"); } + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty.kt") + public void testGenericGetterForJavaOverriddenProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt"); + } + + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty2.kt") + public void testGenericGetterForJavaOverriddenProperty2() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt"); + } + + @Test + @TestMetadata("genericGetterForSyntheticProperty.kt") + public void testGenericGetterForSyntheticProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt"); + } + @Test @TestMetadata("IntersectionTypesProblem.kt") public void testIntersectionTypesProblem() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.fir.txt new file mode 100644 index 00000000000..e7f0af1949f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.fir.txt @@ -0,0 +1,20 @@ +FILE: test.kt + public final class Base : R|kotlin/Any| { + public constructor(x: R|kotlin/Any|): R|Base| { + super() + } + + public final val x: R|kotlin/Any| = R|/x| + public get(): R|kotlin/Any| + + public final fun getFoo(): R|T| { + ^getFoo (this@R|/Base|.R|/Base.x| as R|T|) + } + + } + public final fun bar(some: R|Some|): R|kotlin/Unit| { + lval foo: = R|/some|.# + lval baz: = R|/some|.# + lval getFoo: = R|/some|.R|/Base.getFoo#|<>() + lval getBaz: R|kotlin/String| = R|/some|.R|/Base.getFoo|() + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt new file mode 100644 index 00000000000..69b94e0efe0 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt @@ -0,0 +1,21 @@ +// FILE: Some.java + +public class Some extends Base { + public Some(Object o) { + super(o); + } +} + +// FILE: test.kt + +class Base(val x: Any) { + fun getFoo(): T = x as T +} + +fun bar(some: Some) { + val foo = some.foo + val baz = some.foo + + val getFoo = some.getFoo() + val getBaz = some.getFoo() +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.fir.txt new file mode 100644 index 00000000000..bba47689844 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.fir.txt @@ -0,0 +1,20 @@ +FILE: test.kt + public final class Base : R|kotlin/Any| { + public constructor(foo: R|kotlin/Any|): R|Base| { + super() + } + + internal final val foo: R|kotlin/Any| = R|/foo| + internal get(): R|kotlin/Any| + + public final fun getFoo(): R|T| { + ^getFoo (this@R|/Base|.R|/Base.foo| as R|T|) + } + + } + public final fun bar(some: R|Some|): R|kotlin/Unit| { + lval foo: R|kotlin/Any| = R|/some|.R|/Base.foo| + lval baz: R|kotlin/Any| = R|/some|.R|/Base.foo| + lval getFoo: = R|/some|.R|/Base.getFoo#|<>() + lval getBaz: R|kotlin/String| = R|/some|.R|/Base.getFoo|() + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt new file mode 100644 index 00000000000..b0de7c29dc4 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt @@ -0,0 +1,21 @@ +// FILE: Some.java + +public class Some extends Base { + public Some(Object o) { + super(o); + } +} + +// FILE: test.kt + +class Base(internal val foo: Any) { + fun getFoo(): T = foo as T +} + +fun bar(some: Some) { + val foo = some.foo + val baz = some.foo + + val getFoo = some.getFoo() + val getBaz = some.getFoo() +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.fir.txt new file mode 100644 index 00000000000..24fb5fa2d9b --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.fir.txt @@ -0,0 +1,7 @@ +FILE: test.kt + public final fun bar(some: R|Some|): R|kotlin/Unit| { + lval foo: = R|/some|.# + lval baz: = R|/some|.# + lval getFoo: = R|/some|.R|/Some.getFoo#|<>() + lval getBaz: R|kotlin/String!| = R|/some|.R|/Some.getFoo|() + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt new file mode 100644 index 00000000000..8b37ae78a4c --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL +// FILE: Some.java + +public class Some { + public T getFoo() { + return null; + } +} + +// FILE: test.kt + +fun bar(some: Some) { + val foo = some.foo + val baz = some.foo + + val getFoo = some.getFoo() + val getBaz = some.getFoo() +} 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 3988308ef7d..cc1c8d18e52 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 @@ -6493,6 +6493,24 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.kt"); } + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty.kt") + public void testGenericGetterForJavaOverriddenProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt"); + } + + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty2.kt") + public void testGenericGetterForJavaOverriddenProperty2() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt"); + } + + @Test + @TestMetadata("genericGetterForSyntheticProperty.kt") + public void testGenericGetterForSyntheticProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt"); + } + @Test @TestMetadata("IntersectionTypesProblem.kt") public void testIntersectionTypesProblem() 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 f4b54ee7d24..b4ff28db701 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 @@ -6493,6 +6493,24 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.kt"); } + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty.kt") + public void testGenericGetterForJavaOverriddenProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty.kt"); + } + + @Test + @TestMetadata("genericGetterForJavaOverriddenProperty2.kt") + public void testGenericGetterForJavaOverriddenProperty2() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForJavaOverriddenProperty2.kt"); + } + + @Test + @TestMetadata("genericGetterForSyntheticProperty.kt") + public void testGenericGetterForSyntheticProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/genericGetterForSyntheticProperty.kt"); + } + @Test @TestMetadata("IntersectionTypesProblem.kt") public void testIntersectionTypesProblem() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index ad40013814e..5d1eafdef75 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -18627,6 +18627,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fir/toLong.kt"); } + @Test + @TestMetadata("typeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index b5ffaa65fd7..d7e377fb503 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -18627,6 +18627,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fir/toLong.kt"); } + @Test + @TestMetadata("typeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java index b7e0db4cb83..c39ac702253 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java @@ -2882,6 +2882,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI runTest("compiler/testData/ir/irText/firProblems/typeParameterFromJavaClass.kt"); } + @Test + @TestMetadata("TypeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java index 60ab570e4f2..2f4aa25c965 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java @@ -2882,6 +2882,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { runTest("compiler/testData/ir/irText/firProblems/typeParameterFromJavaClass.kt"); } + @Test + @TestMetadata("TypeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt index 2f74ed2fa46..f2e3c508a66 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt @@ -195,8 +195,13 @@ class JavaClassUseSiteMemberScope( val candidateReturnType = candidate.returnTypeRef.toConeKotlinTypeProbablyFlexible(session, typeParameterStack) candidateSymbol.takeIf { - // TODO: Decide something for the case when property type is not computed yet - expectedReturnType == null || AbstractTypeChecker.isSubtypeOf(session.typeContext, candidateReturnType, expectedReturnType) + when { + candidate.isJavaOrEnhancement -> + // TODO: Decide something for the case when property type is not computed yet + expectedReturnType == null || + AbstractTypeChecker.isSubtypeOf(session.typeContext, candidateReturnType, expectedReturnType) + else -> false + } } } } @@ -215,7 +220,7 @@ class JavaClassUseSiteMemberScope( candidate.valueParameters.single().returnTypeRef.toConeKotlinTypeProbablyFlexible(session, typeParameterStack) candidateSymbol.takeIf { - AbstractTypeChecker.equalTypes(session.typeContext, parameterType, propertyType) + candidate.isJavaOrEnhancement && AbstractTypeChecker.equalTypes(session.typeContext, parameterType, propertyType) } } } diff --git a/compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt b/compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt new file mode 100644 index 00000000000..538c1082c31 --- /dev/null +++ b/compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt @@ -0,0 +1,37 @@ +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_K1: JVM_IR +// ISSUE: KT-59038 + +// FILE: C.java +abstract class C extends B { + protected C(A a) { + super(a); + } +} + +// FILE: test.kt +private class D(a: A) : C(a) + +open class A + +class E : A() + +open class B(private val a: A) { + open fun getA(): T { + return a as T + } +} + +fun box(): String { + val a = A() + val da = D(a) + val aa = da.getA() + if (a !== aa) return "FAIL 1" + + val e = E() + val de = D(e) + val ee = de.getA() + if (e !== ee) return "FAIL 2" + + return "OK" +} diff --git a/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.ir.txt b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.ir.txt new file mode 100644 index 00000000000..54879be92c0 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.ir.txt @@ -0,0 +1,85 @@ +FILE fqName: fileName:/test.kt + CLASS CLASS name:D modality:FINAL visibility:private superTypes:[.C] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.D + CONSTRUCTOR visibility:public <> (a:.A) returnType:.D [primary] + VALUE_PARAMETER name:a index:0 type:.A + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'protected/*protected and package*/ constructor (a: @[FlexibleNullability] .A?) declared in .C' + a: GET_VAR 'a: .A declared in .D.' type=.A origin=null + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:D modality:FINAL visibility:private superTypes:[.C]' + FUN FAKE_OVERRIDE name:getA visibility:public modality:OPEN ($this:.B) returnType:T of .D.getA [fake_override] + overridden: + public open fun getA (): T of .C.getA declared in .C + TYPE_PARAMETER name:T index:0 variance: superTypes:[.A] reified:false + $this: VALUE_PARAMETER name: type:.B + 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 declared in .C + $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 .C + $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 .C + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:OPEN visibility:public superTypes:[kotlin.Any]' + 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 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 + CLASS CLASS name:B modality:OPEN visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + CONSTRUCTOR visibility:public <> (a:.A) returnType:.B [primary] + VALUE_PARAMETER name:a index:0 type:.A + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:OPEN visibility:public superTypes:[kotlin.Any]' + PROPERTY name:a visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:.A visibility:private [final] + EXPRESSION_BODY + GET_VAR 'a: .A declared in .B.' type=.A origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.B) returnType:.A + correspondingProperty: PROPERTY name:a visibility:private modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): .A declared in .B' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:.A visibility:private [final]' type=.A origin=null + receiver: GET_VAR ': .B declared in .B.' type=.B origin=null + FUN name:getA visibility:public modality:OPEN ($this:.B) returnType:T of .B.getA + TYPE_PARAMETER name:T index:0 variance: superTypes:[.A] reified:false + $this: VALUE_PARAMETER name: type:.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun getA (): T of .B.getA declared in .B' + TYPE_OP type=T of .B.getA origin=CAST typeOperand=T of .B.getA + CALL 'private final fun (): .A declared in .B' type=.A origin=GET_PROPERTY + $this: GET_VAR ': .B declared in .B.getA' type=.B 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 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 diff --git a/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt new file mode 100644 index 00000000000..aedeea53279 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt @@ -0,0 +1,22 @@ +// FIR_IDENTICAL +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_K1: JVM_IR +// ISSUE: KT-59038 + +// FILE: C.java +abstract class C extends B { + protected C(A a) { + super(a); + } +} + +// FILE: test.kt +private class D(a: A) : C(a) + +open class A + +open class B(private val a: A) { + open fun getA(): T { + return a as T + } +} diff --git a/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt.txt b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt.txt new file mode 100644 index 00000000000..a8857c4974a --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt.txt @@ -0,0 +1,34 @@ +private class D : C { + constructor(a: A) /* primary */ { + super/*C*/(a = a) + /* () */ + + } + +} + +open class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +open class B { + constructor(a: A) /* primary */ { + super/*Any*/() + /* () */ + + } + + private val a: A + field = a + private get + + open fun getA(): T { + return .() as T + } + +} diff --git a/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.sig.kt.txt b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.sig.kt.txt new file mode 100644 index 00000000000..6af98322c25 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.sig.kt.txt @@ -0,0 +1,52 @@ +// CHECK: +// Mangled name: A +// Public signature: /A|null[0] +open class A { + // CHECK: + // Mangled name: A#(){} + // Public signature: /A.|-5645683436151566731[0] + constructor() /* primary */ + +} + +// CHECK: +// Mangled name: B +// Public signature: /B|null[0] +open class B { + // CHECK: + // Mangled name: B{}a + // Public signature: /B.a|-1200697420457237799[0] + private val a: A + // CHECK JVM_IR: + // Mangled name: B#(){}A + // Public signature: /B.a.|736568356921033436[0] + private get + + // CHECK: + // Mangled name: B#(A){} + // Public signature: /B.|-3166999336802030902[0] + constructor(a: A) /* primary */ + + // CHECK JVM_IR: + // Mangled name: B#getA(){0§}0:0 + // Public signature: /B.getA|6265629995120627543[0] + open fun getA(): T + +} + +// CHECK: +// Mangled name: D +// Public signature: [ File '' <- /D|null[0] ] +private class D : C { + // CHECK: + // Mangled name: D#(A){} + // Public signature: /D.|-3166999336802030902[0] + constructor(a: A) /* primary */ + + // CHECK: + // Mangled name: D#getA(){0§}0:0 + // Public signature: /D.getA|6265629995120627543[0] + /* fake */ override fun getA(): T + +} + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index e04fd0bac9e..c9c2c181f16 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -18627,6 +18627,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/toLong.kt"); } + @Test + @TestMetadata("typeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 6ae2e52d1bf..4362c3b3811 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -18627,6 +18627,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fir/toLong.kt"); } + @Test + @TestMetadata("typeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/codegen/box/fir/typeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java index dadafe2b3cf..c4beb3ea5ad 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java @@ -2882,6 +2882,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest runTest("compiler/testData/ir/irText/firProblems/typeParameterFromJavaClass.kt"); } + @Test + @TestMetadata("TypeParameterInClashingAccessor.kt") + public void testTypeParameterInClashingAccessor() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/TypeParameterInClashingAccessor.kt"); + } + @Test @TestMetadata("TypeParameterInNestedClass.kt") public void testTypeParameterInNestedClass() throws Exception {