From f20e5daa92a1abe94b4d603854c38fbdbd3d8e7a Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 11 Jan 2023 19:56:29 +0100 Subject: [PATCH] K2: fix property VS field resolve in anonymous class case Related to KT-55017, KT-50082 --- ...nosisCompilerFirTestdataTestGenerated.java | 6 ++++ ...TouchedTilContractsPhaseTestGenerated.java | 5 ++++ ...ndKotlinPropertyReferenceFromInner.fir.txt | 29 +++++++++++++++++++ ...ieldAndKotlinPropertyReferenceFromInner.kt | 25 ++++++++++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 ++++ .../JvmPlatformOverloadsConflictResolver.kt | 3 +- 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt 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 fbc506e323a..0de50e087df 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 @@ -3589,6 +3589,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/fieldPropertyShadow.kt"); } + @Test + @TestMetadata("javaFieldAndKotlinPropertyReferenceFromInner.kt") + public void testJavaFieldAndKotlinPropertyReferenceFromInner() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt"); + } + @Test @TestMetadata("propertyAndTwoFields.kt") public void testPropertyAndTwoFields() 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 6886fa8e4d1..a5f309ee32c 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 @@ -3166,6 +3166,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/fieldPropertyShadow.kt"); } + @TestMetadata("javaFieldAndKotlinPropertyReferenceFromInner.kt") + public void testJavaFieldAndKotlinPropertyReferenceFromInner() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt"); + } + @TestMetadata("propertyAndTwoFields.kt") public void testPropertyAndTwoFields() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/propertyAndTwoFields.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.fir.txt b/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.fir.txt new file mode 100644 index 00000000000..040e6cf3835 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.fir.txt @@ -0,0 +1,29 @@ +FILE: test.kt + public final fun box(): R|kotlin/String| { + lval x: R|| = object : R|base/Jaba| { + private constructor(): R|| { + super() + } + + private final val a: R|kotlin/String| = String(OK) + private get(): R|kotlin/String| + + local final inner class S : R|kotlin/Any| { + public .constructor(): R|.S| { + super() + } + + public final fun foo(): R|kotlin/String| { + ^foo this@R|/|.R|/.a| + } + + } + + public final fun bar(): R|kotlin/String| { + ^bar this@R|/|.R|/.S.S|().R|/foo|() + } + + } + + ^box R|/x|.R|/.bar|() + } diff --git a/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt b/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt new file mode 100644 index 00000000000..ca0b98b5818 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt @@ -0,0 +1,25 @@ +// FILE: Jaba.java + +package base; + +public class Jaba { + protected String a = "FAIL"; +} + +// FILE: test.kt + +import base.Jaba + +fun box(): String { + val x = object : Jaba() { + private val a: String = "OK" + inner class S { + // Should be resolved to a property + fun foo() = a + } + + fun bar() = S().foo() + } + + return x.bar() +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index 653ab068b61..e60e9ebad65 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -3589,6 +3589,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/fieldPropertyShadow.kt"); } + @Test + @TestMetadata("javaFieldAndKotlinPropertyReferenceFromInner.kt") + public void testJavaFieldAndKotlinPropertyReferenceFromInner() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt"); + } + @Test @TestMetadata("propertyAndTwoFields.kt") public void testPropertyAndTwoFields() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index b4982edab54..7cd0457bc72 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -3589,6 +3589,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/fieldPropertyShadow.kt"); } + @Test + @TestMetadata("javaFieldAndKotlinPropertyReferenceFromInner.kt") + public void testJavaFieldAndKotlinPropertyReferenceFromInner() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyVsField/javaFieldAndKotlinPropertyReferenceFromInner.kt"); + } + @Test @TestMetadata("propertyAndTwoFields.kt") public void testPropertyAndTwoFields() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmPlatformOverloadsConflictResolver.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmPlatformOverloadsConflictResolver.kt index c03bef2ab22..0cec406cdaa 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmPlatformOverloadsConflictResolver.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmPlatformOverloadsConflictResolver.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls.jvm import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.fir.containingClassLookupTag +import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirField import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.languageVersionSettings @@ -84,7 +85,7 @@ class JvmPlatformOverloadsConflictResolver( private fun ConeClassLikeLookupTag.strictlyDerivedFrom(other: ConeClassLikeLookupTag): Boolean { if (this == other) return false val session = inferenceComponents.session - val thisClass = this.toFirRegularClassSymbol(session)?.fir ?: return false + val thisClass = this.toSymbol(session)?.fir as? FirClass ?: return false return thisClass.isSubclassOf(other, session, isStrict = true) }