diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 690875a4a50..e083b71f35d 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -22647,6 +22647,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt"); } + @TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt") + public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception { + runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt"); + } + @TestMetadata("SetterHasHigherAccess.kt") public void testSetterHasHigherAccess() throws Exception { runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.kt"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/UnsupportedSyntheticCallableReferenceChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/UnsupportedSyntheticCallableReferenceChecker.kt index 1f24cde9a6a..da68a2ff29a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/UnsupportedSyntheticCallableReferenceChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/UnsupportedSyntheticCallableReferenceChecker.kt @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.resolve.jvm.checkers import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.diagnostics.Errors.CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED import org.jetbrains.kotlin.resolve.calls.callUtil.isCallableReference import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker @@ -28,7 +30,16 @@ class UnsupportedSyntheticCallableReferenceChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { // TODO: support references to synthetic Java extension properties (KT-8575) if (resolvedCall.call.isCallableReference() && resolvedCall.resultingDescriptor is SyntheticJavaPropertyDescriptor) { - context.trace.report(UNSUPPORTED.on(reportOn, "reference to the synthetic extension property for a Java get/set method")) + val diagnostic = if ( + context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) && + context.languageVersionSettings.supportsFeature(LanguageFeature.ReferencesToSyntheticJavaProperties) + ) { + CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY.on(reportOn) + } else { + UNSUPPORTED.on(reportOn, "reference to the synthetic extension property for a Java get/set method") + } + + context.trace.report(diagnostic) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 84edd31a911..9dbc8cefccf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -784,6 +784,8 @@ public interface Errors { DiagnosticFactory0 NULLABLE_TYPE_IN_CLASS_LITERAL_LHS = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS = DiagnosticFactory1.create(ERROR); + DiagnosticFactory0 CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY = DiagnosticFactory0.create(WARNING); + // Destructuring-declarations DiagnosticFactory0 INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION = DiagnosticFactory0.create(ERROR, DEFAULT); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 397d14f7f26..9c9fd69d981 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -965,6 +965,8 @@ public class DefaultErrorMessages { MAP.put(NULLABLE_TYPE_IN_CLASS_LITERAL_LHS, "Type in a class literal must not be nullable"); MAP.put(EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS, "Expression in a class literal has a nullable type ''{0}'', use !! to make the type non-nullable", RENDER_TYPE); + MAP.put(CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY, "References to the synthetic extension properties for a Java get/set methods aren't supported fully, please use reference to a method"); + //Inline MAP.put(NON_PUBLIC_CALL_FROM_PUBLIC_INLINE, "Public-API inline function cannot access non-public-API ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); MAP.put(PRIVATE_CLASS_MEMBER_FROM_INLINE, "Non-private inline function cannot access members of private classes: ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.fir.kt new file mode 100644 index 00000000000..e9211bab3cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +ReferencesToSyntheticJavaProperties +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: KotlinFile.kt + +fun call(c: Any) {} + +fun test() { + JavaClass::foo + call(JavaClass::foo) +} + +// FILE: JavaClass.java + +public class JavaClass { + public String getFoo() {} +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt new file mode 100644 index 00000000000..eb37f29c6a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +ReferencesToSyntheticJavaProperties +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: KotlinFile.kt + +fun call(c: Any) {} + +fun test() { + JavaClass::foo + call(JavaClass::foo) +} + +// FILE: JavaClass.java + +public class JavaClass { + public String getFoo() {} +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.txt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.txt new file mode 100644 index 00000000000..94b325e147a --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.txt @@ -0,0 +1,12 @@ +package + +public fun call(/*0*/ c: kotlin.Any): kotlin.Unit +public fun test(): kotlin.Unit + +public open class JavaClass { + public constructor JavaClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun getFoo(): kotlin.String! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt index 2d20cf8e244..b79144e3f60 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt @@ -1,6 +1,14 @@ +// !LANGUAGE: -ReferencesToSyntheticJavaProperties +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + // FILE: KotlinFile.kt -fun bar() = JavaClass::foo +fun call(c: Any) {} + +fun test() { + JavaClass::foo + call(JavaClass::foo) +} // FILE: JavaClass.java diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.kt index 3db13325d46..ecb38855901 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.kt @@ -1,6 +1,14 @@ +// !LANGUAGE: -ReferencesToSyntheticJavaProperties +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + // FILE: KotlinFile.kt -fun bar() = JavaClass::foo +fun call(c: Any) {} + +fun test() { + JavaClass::foo + call(JavaClass::foo) +} // FILE: JavaClass.java diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.txt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.txt index 939781dbe26..94b325e147a 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.txt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.txt @@ -1,6 +1,7 @@ package -public fun bar(): kotlin.reflect.KProperty1 +public fun call(/*0*/ c: kotlin.Any): kotlin.Unit +public fun test(): kotlin.Unit public open class JavaClass { public constructor JavaClass() diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 75488700f17..aafd7625de7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -22729,6 +22729,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt"); } + @TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt") + public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception { + runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt"); + } + @TestMetadata("SetterHasHigherAccess.kt") public void testSetterHasHigherAccess() throws Exception { runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index f99e18f50a0..e13497ce314 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -22649,6 +22649,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt"); } + @TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt") + public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception { + runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt"); + } + @TestMetadata("SetterHasHigherAccess.kt") public void testSetterHasHigherAccess() throws Exception { runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 92f5460f8ec..96687916085 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -148,6 +148,7 @@ enum class LanguageFeature( NewDataFlowForTryExpressions(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED), FunctionReferenceWithDefaultValueAsOtherType(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED), NonStrictOnlyInputTypesChecks(KOTLIN_1_4), + ReferencesToSyntheticJavaProperties(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED), // ------ // Next features can be enabled regardless of new inference