Add feature that allows references to synthetic properties with warning
See KT-35933 for details
This commit is contained in:
Generated
+5
@@ -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");
|
||||
|
||||
+12
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,6 +784,8 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtExpression> NULLABLE_TYPE_IN_CLASS_LITERAL_LHS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Destructuring-declarations
|
||||
|
||||
DiagnosticFactory0<KtDestructuringDeclaration> INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
|
||||
+2
@@ -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);
|
||||
|
||||
+17
@@ -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() {}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +NewInference +ReferencesToSyntheticJavaProperties
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
// FILE: KotlinFile.kt
|
||||
|
||||
fun call(c: Any) {}
|
||||
|
||||
fun test() {
|
||||
JavaClass::<!CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY!>foo<!>
|
||||
call(JavaClass::<!CALLABLE_REFERENCE_TO_JAVA_SYNTHETIC_PROPERTY!>foo<!>)
|
||||
}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
public String getFoo() {}
|
||||
}
|
||||
+12
@@ -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
|
||||
}
|
||||
+9
-1
@@ -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
|
||||
|
||||
|
||||
+9
-1
@@ -1,6 +1,14 @@
|
||||
// !LANGUAGE: -ReferencesToSyntheticJavaProperties
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
// FILE: KotlinFile.kt
|
||||
|
||||
fun bar() = JavaClass::<!UNSUPPORTED!>foo<!>
|
||||
fun call(c: Any) {}
|
||||
|
||||
fun test() {
|
||||
JavaClass::<!UNSUPPORTED!>foo<!>
|
||||
call(JavaClass::<!UNSUPPORTED!>foo<!>)
|
||||
}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package
|
||||
|
||||
public fun bar(): kotlin.reflect.KProperty1<JavaClass, kotlin.String!>
|
||||
public fun call(/*0*/ c: kotlin.Any): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public open class JavaClass {
|
||||
public constructor JavaClass()
|
||||
|
||||
@@ -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");
|
||||
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user