2/2 FirUnsupportedSyntheticCallableReferenceChecker: don't report error on FirJavaOverriddenSyntheticPropertySymbol
Meta issue: KT-8575 ^KT-58061 Fixed Review: https://jetbrains.team/p/kt/reviews/9677 This commit fixes an inconsistency between FirUnsupportedSyntheticCallableReferenceChecker and UnsupportedSyntheticCallableReferenceChecker In K1 such properties were not considered synthetic and are called JavaPropertyDescriptor. That's why we need to do an additional check in K2 checker, while in K1 we didn't need to do it Also see the previous commit for more related tests that already was green without this fix but are related to KT-58061 problem
This commit is contained in:
+12
@@ -4323,6 +4323,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOverridesKotlinProperty.kt")
|
||||
public void testJavaOverridesKotlinProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/javaOverridesKotlinProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localVariable.kt")
|
||||
public void testLocalVariable() throws Exception {
|
||||
@@ -4352,6 +4358,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
public void testSyntheticProperties() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesOnJavaAnnotation.kt")
|
||||
public void testSyntheticPropertiesOnJavaAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticPropertiesOnJavaAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -4323,6 +4323,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOverridesKotlinProperty.kt")
|
||||
public void testJavaOverridesKotlinProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/javaOverridesKotlinProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localVariable.kt")
|
||||
public void testLocalVariable() throws Exception {
|
||||
@@ -4352,6 +4358,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
public void testSyntheticProperties() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesOnJavaAnnotation.kt")
|
||||
public void testSyntheticPropertiesOnJavaAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticPropertiesOnJavaAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -4323,6 +4323,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOverridesKotlinProperty.kt")
|
||||
public void testJavaOverridesKotlinProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/javaOverridesKotlinProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localVariable.kt")
|
||||
public void testLocalVariable() throws Exception {
|
||||
@@ -4352,6 +4358,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
public void testSyntheticProperties() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesOnJavaAnnotation.kt")
|
||||
public void testSyntheticPropertiesOnJavaAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticPropertiesOnJavaAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -4329,6 +4329,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOverridesKotlinProperty.kt")
|
||||
public void testJavaOverridesKotlinProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/javaOverridesKotlinProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localVariable.kt")
|
||||
public void testLocalVariable() throws Exception {
|
||||
@@ -4358,6 +4364,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
public void testSyntheticProperties() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesOnJavaAnnotation.kt")
|
||||
public void testSyntheticPropertiesOnJavaAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticPropertiesOnJavaAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.toResolvedCallableReference
|
||||
import org.jetbrains.kotlin.fir.java.symbols.FirJavaOverriddenSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
|
||||
|
||||
/**
|
||||
@@ -31,8 +31,12 @@ object FirUnsupportedSyntheticCallableReferenceChecker : FirExpressionChecker<Fi
|
||||
// We allow resolution of top-level callable references to synthetic Java extension properties in the delegate position. See KT-47299
|
||||
if (parent is FirProperty && parent.delegate === expression) return
|
||||
|
||||
val resolvedSymbol = expression.toResolvedCallableReference()?.resolvedSymbol
|
||||
if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.ReferencesToSyntheticJavaProperties) &&
|
||||
expression.toResolvedCallableReference()?.resolvedSymbol is FirSyntheticPropertySymbol
|
||||
resolvedSymbol is FirSyntheticPropertySymbol &&
|
||||
// In K1 such properties were not considered synthetic and are called JavaPropertyDescriptor.
|
||||
// That's why we need to do an additional check in K2 checker, while in K1 we didn't need to do it
|
||||
resolvedSymbol !is FirJavaOverriddenSyntheticPropertySymbol
|
||||
) {
|
||||
reporter.reportOn(
|
||||
expression.calleeReference.source,
|
||||
|
||||
+16
-2
@@ -14,8 +14,7 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
* Frontend IR creates such kind a symbol when a Java class is asked for a property which
|
||||
* exists in one of its base Kotlin classes, and the Java class itself contains the bound getter.
|
||||
*
|
||||
* The typical example:
|
||||
*
|
||||
* ## Example 1
|
||||
* ```
|
||||
* abstract class SomeKotlinClass {
|
||||
* abstract val foo: Int
|
||||
@@ -26,6 +25,21 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
* public int getFoo() { return 42; }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* ## Example 2
|
||||
* Another use-case is "properties" of Java annotations:
|
||||
* ```
|
||||
* public @interface JavaAnnotation {
|
||||
* public String javaProperty() default ""; // Java method which is considered property in Kotlin,
|
||||
* // because methods in Java annotations can't have parameters
|
||||
* }
|
||||
*
|
||||
* fun main(annotation: JavaAnnotation) {
|
||||
* annotation.javaProperty // FirJavaOverriddenSyntheticPropertySymbol
|
||||
* }
|
||||
* ```
|
||||
* The mental model is that in Kotlin world annotations can have only constructor-properties.
|
||||
* And Java "overrides" Kotlin's "base Annotation" class (yes, technically there is no base class for annotations).
|
||||
*/
|
||||
class FirJavaOverriddenSyntheticPropertySymbol(
|
||||
propertyId: CallableId,
|
||||
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: -ReferencesToSyntheticJavaProperties
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo extends Base {
|
||||
@Override
|
||||
public int getFoo() {
|
||||
return super.getFoo();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Main.kt
|
||||
open class Base {
|
||||
open val foo: Int = 904
|
||||
}
|
||||
|
||||
val prop = Foo::foo
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: -ReferencesToSyntheticJavaProperties
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// FILE: AnnInterface.java
|
||||
public @interface AnnInterface {
|
||||
public String javaMethod() default "";
|
||||
}
|
||||
|
||||
// FILE: Main.kt
|
||||
val prop = AnnInterface::javaMethod
|
||||
Generated
+12
@@ -4329,6 +4329,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaOverridesKotlinProperty.kt")
|
||||
public void testJavaOverridesKotlinProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/javaOverridesKotlinProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localVariable.kt")
|
||||
public void testLocalVariable() throws Exception {
|
||||
@@ -4358,6 +4364,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
public void testSyntheticProperties() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesOnJavaAnnotation.kt")
|
||||
public void testSyntheticPropertiesOnJavaAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticPropertiesOnJavaAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user