diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.kt similarity index 96% rename from compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt rename to compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.kt index 3b9feb647a6..addedb1513a 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt +++ b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.kt @@ -74,9 +74,9 @@ class Foo { } fun test_4(foo: Foo) { - foo.x // should be error + foo.x // should be error } fun test_5(x: D) { x.isGood -} \ No newline at end of file +} diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.txt b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.txt similarity index 96% rename from compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.txt rename to compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.txt index 51482dbde15..79d58c33d0e 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.txt +++ b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.txt @@ -22,7 +22,7 @@ FILE: main.kt } public final fun test_4(foo: R|Foo|): R|kotlin/Unit| { - R|/foo|.R|/Foo.x| + R|/foo|.# } public final fun test_5(x: R|D|): R|kotlin/Unit| { R|/x|.R|/D.isGood| diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 6658ede18e8..ef937ca6f5a 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1689,11 +1689,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/problems/innerClassHierarchy.kt"); } - @TestMetadata("javaAccessorConversion.kt") - public void testJavaAccessorConversion() throws Exception { - runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt"); - } - @TestMetadata("javaQualifier.kt") public void testJavaQualifier() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaQualifier.kt"); @@ -1732,6 +1727,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @TestMetadata("javaAccessorConversion.kt") + public void testJavaAccessorConversion() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.kt"); + } + @TestMetadata("noBackingFieldForExtension.kt") public void testNoBackingFieldForExtension() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index e180d48d23f..90f57b61364 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1689,11 +1689,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/problems/innerClassHierarchy.kt"); } - @TestMetadata("javaAccessorConversion.kt") - public void testJavaAccessorConversion() throws Exception { - runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt"); - } - @TestMetadata("javaQualifier.kt") public void testJavaQualifier() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaQualifier.kt"); @@ -1732,6 +1727,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @TestMetadata("javaAccessorConversion.kt") + public void testJavaAccessorConversion() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorConversion.kt"); + } + @TestMetadata("noBackingFieldForExtension.kt") public void testNoBackingFieldForExtension() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/properties/noBackingFieldForExtension.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index b8d9be17225..a006dd6d5b6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -6,17 +6,17 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.declarations.isStatic import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty import org.jetbrains.kotlin.fir.scopes.FirScope +import org.jetbrains.kotlin.fir.scopes.ProcessorAction +import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctionsAndSelf import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirAccessorSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol +import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName @@ -52,6 +52,8 @@ class FirSyntheticPropertiesScope( val getterReturnType = (getter.returnTypeRef as? FirResolvedTypeRef)?.type if ((getterReturnType as? ConeClassLikeType)?.lookupTag?.classId == StandardClassIds.Unit) return + if (!getterSymbol.hasJavaOverridden()) return + var matchingSetter: FirSimpleFunction? = null if (getterReturnType != null) { val setterName = setterNameByGetterName(getterName) @@ -79,6 +81,20 @@ class FirSyntheticPropertiesScope( processor(property.symbol) } + private fun FirFunctionSymbol<*>.hasJavaOverridden(): Boolean { + var result = false + baseScope.processOverriddenFunctionsAndSelf(this) { + if (it.unwrapOverridden().fir.origin == FirDeclarationOrigin.Enhancement) { + result = true + ProcessorAction.STOP + } else { + ProcessorAction.NEXT + } + } + + return result + } + override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) { val getterNames = possibleGetterNamesByPropertyName(name) for (getterName in getterNames) { @@ -118,4 +134,3 @@ class FirSyntheticPropertiesScope( private const val IS_PREFIX = "is" } } - diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt index 58bbf2ee72e..486193222c8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt @@ -21,3 +21,12 @@ inline fun > E.unwrapOverriddenOnce(): E { return this } + +inline fun > E.unwrapOverridden(): E { + var current = this + while (current.overriddenSymbol != null) { + current = current.overriddenSymbol as E + } + + return current +} diff --git a/compiler/testData/codegen/box/objects/objectLiteralInClass.kt b/compiler/testData/codegen/box/objects/objectLiteralInClass.kt index 28730191e6e..db32a1dab6a 100644 --- a/compiler/testData/codegen/box/objects/objectLiteralInClass.kt +++ b/compiler/testData/codegen/box/objects/objectLiteralInClass.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR - class C { val s = "OK" diff --git a/compiler/testData/codegen/box/properties/kt4252.kt b/compiler/testData/codegen/box/properties/kt4252.kt index 1590f9ab50d..f14f069901d 100644 --- a/compiler/testData/codegen/box/properties/kt4252.kt +++ b/compiler/testData/codegen/box/properties/kt4252.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class CallbackBlock {} public class Foo @@ -21,4 +20,4 @@ fun box() : String { if (foo.getBar() != 1) return "Fail"; return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt index 75ef68bc4a2..16bc04a0a8b 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt @@ -1,7 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// Note: does not pass on FIR because of non-prohibited Kotlin synthetic properties, -// fun getS() = s is considered to be recursive here :( -// It's a question to be discussed in Dec 2019. Muted at this moment. // WITH_RUNTIME // FILE: lateinit.kt private lateinit var s: String diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt index b736b3ddb69..caa3418f5b5 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt @@ -1,7 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// Note: does not pass on FIR because of non-prohibited Kotlin synthetic properties, -// fun getS() = s is considered to be recursive here :( -// It's a question to be discussed in Dec 2019. Muted at this moment. // FILE: lateinit.kt private lateinit var s: String diff --git a/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt deleted file mode 100644 index ffd7499b218..00000000000 --- a/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -class B { - fun getA() = a -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.kt b/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.kt index 87ffa3dd7e6..28b5a5a78ad 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class B { fun getA() = a } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt index 0be689aa089..7371bbcfc79 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt @@ -14,8 +14,8 @@ fun foo(k: KotlinClass2) { useInt(k.something2) useInt(k.getSomethingKotlin1()) useInt(k.getSomethingKotlin2()) - k.somethingKotlin1 - k.somethingKotlin2 + k.somethingKotlin1 + k.somethingKotlin2 } fun useInt(i: Int) {} @@ -28,4 +28,4 @@ public class JavaClass1 { // FILE: JavaClass2.java public class JavaClass2 extends KotlinClass1 { public int getSomething2() { return 1; } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt index e8c069e2d88..c10255ae997 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt @@ -9,7 +9,7 @@ fun foo(javaClass: JavaClass, kotlinClass: KotlinClass) { javaClass.something = 1 javaClass.Something useInt(kotlinClass.getSomething()) - kotlinClass.something + kotlinClass.something } fun useInt(i: Int) {} @@ -17,4 +17,4 @@ fun useInt(i: Int) {} // FILE: JavaClass.java public class JavaClass { public int getSomething() { return 1; } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt index 99d47ef1928..783f074519a 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt @@ -22,9 +22,9 @@ fun foo(k: KotlinClass) { useString(k.something3) k.setSomething4("") - k.something4 += "" + k.something4 += "" k.setSomething4(null) - k.something4 = null + k.something4 = null useString(k.getSomething5()) useString(k.something5)