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:
Nikita Bobko
2023-04-19 12:07:15 +02:00
committed by Space Team
parent 11f376ae84
commit 8314812ef9
9 changed files with 109 additions and 4 deletions
@@ -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");
}
}
}
@@ -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");
}
}
}
@@ -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");
}
}
}
@@ -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");
}
}
}
@@ -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,
@@ -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,
@@ -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
@@ -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
@@ -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");
}
}
}