FIR: Do not create synthetic properties for non-Java accessors
^KT-35495 Fixed
This commit is contained in:
+2
-2
@@ -74,9 +74,9 @@ class Foo {
|
||||
}
|
||||
|
||||
fun test_4(foo: Foo) {
|
||||
foo.x // should be error
|
||||
foo.<!UNRESOLVED_REFERENCE!>x<!> // should be error
|
||||
}
|
||||
|
||||
fun test_5(x: D) {
|
||||
x.isGood
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ FILE: main.kt
|
||||
|
||||
}
|
||||
public final fun test_4(foo: R|Foo|): R|kotlin/Unit| {
|
||||
R|<local>/foo|.R|/Foo.x|
|
||||
R|<local>/foo|.<Unresolved name: x>#
|
||||
}
|
||||
public final fun test_5(x: R|D|): R|kotlin/Unit| {
|
||||
R|<local>/x|.R|/D.isGood|
|
||||
Generated
+5
-5
@@ -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");
|
||||
|
||||
+5
-5
@@ -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");
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,3 +21,12 @@ inline fun <reified E : FirCallableSymbol<*>> E.unwrapOverriddenOnce(): E {
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
inline fun <reified E : FirCallableSymbol<*>> E.unwrapOverridden(): E {
|
||||
var current = this
|
||||
while (current.overriddenSymbol != null) {
|
||||
current = current.overriddenSymbol as E
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
class C {
|
||||
|
||||
val s = "OK"
|
||||
|
||||
+1
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
-4
@@ -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
|
||||
|
||||
-4
@@ -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
|
||||
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
class B {
|
||||
fun getA() = a
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
class B {
|
||||
fun getA() = <!UNRESOLVED_REFERENCE!>a<!>
|
||||
}
|
||||
+3
-3
@@ -14,8 +14,8 @@ fun foo(k: KotlinClass2) {
|
||||
useInt(k.something2)
|
||||
useInt(k.getSomethingKotlin1())
|
||||
useInt(k.getSomethingKotlin2())
|
||||
k.somethingKotlin1
|
||||
k.somethingKotlin2
|
||||
k.<!UNRESOLVED_REFERENCE!>somethingKotlin1<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>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; }
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ fun foo(javaClass: JavaClass, kotlinClass: KotlinClass) {
|
||||
javaClass.something = 1
|
||||
javaClass.<!UNRESOLVED_REFERENCE!>Something<!>
|
||||
useInt(kotlinClass.getSomething())
|
||||
kotlinClass.something
|
||||
kotlinClass.<!UNRESOLVED_REFERENCE!>something<!>
|
||||
}
|
||||
|
||||
fun useInt(i: Int) {}
|
||||
@@ -17,4 +17,4 @@ fun useInt(i: Int) {}
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass {
|
||||
public int getSomething() { return 1; }
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -22,9 +22,9 @@ fun foo(k: KotlinClass) {
|
||||
useString(k.something3)
|
||||
|
||||
k.setSomething4("")
|
||||
k.something4 += ""
|
||||
k.<!UNRESOLVED_REFERENCE, VARIABLE_EXPECTED!>something4<!> += ""
|
||||
k.<!INAPPLICABLE_CANDIDATE!>setSomething4<!>(null)
|
||||
k.something4 = null
|
||||
k.<!UNRESOLVED_REFERENCE!>something4<!> = null
|
||||
|
||||
useString(k.getSomething5())
|
||||
useString(k.something5)
|
||||
|
||||
Reference in New Issue
Block a user