KT-8575 Fix warnings for Java synthetic properties

This commit is contained in:
Pavel Mikhailovskii
2022-10-10 22:35:10 +02:00
committed by teamcity
parent 26dc010d30
commit f4bdf54601
13 changed files with 37 additions and 59 deletions
@@ -31541,6 +31541,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.kt");
}
@Test
@TestMetadata("FullySupportedSyntheticJavaPropertyReference.kt")
public void testFullySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FullySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("GenericClass.kt")
public void testGenericClass() throws Exception {
@@ -31643,12 +31649,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt");
}
@Test
@TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt")
public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("SetterHasHigherAccess.kt")
public void testSetterHasHigherAccess() throws Exception {
@@ -31541,6 +31541,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.kt");
}
@Test
@TestMetadata("FullySupportedSyntheticJavaPropertyReference.kt")
public void testFullySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FullySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("GenericClass.kt")
public void testGenericClass() throws Exception {
@@ -31643,12 +31649,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt");
}
@Test
@TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt")
public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("SetterHasHigherAccess.kt")
public void testSetterHasHigherAccess() throws Exception {
@@ -31541,6 +31541,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.kt");
}
@Test
@TestMetadata("FullySupportedSyntheticJavaPropertyReference.kt")
public void testFullySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FullySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("GenericClass.kt")
public void testGenericClass() throws Exception {
@@ -31643,12 +31649,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt");
}
@Test
@TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt")
public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("SetterHasHigherAccess.kt")
public void testSetterHasHigherAccess() throws Exception {
@@ -18,8 +18,7 @@ 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.diagnostics.Errors.UNSUPPORTED_FEATURE
import org.jetbrains.kotlin.psi.KtPropertyDelegate
import org.jetbrains.kotlin.psi.psiUtil.unwrapParenthesesLabelsAndAnnotationsDeeply
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
@@ -37,16 +36,11 @@ class UnsupportedSyntheticCallableReferenceChecker : CallChecker {
if (callableReferenceExpression.unwrapParenthesesLabelsAndAnnotationsDeeply() is KtPropertyDelegate) return
if (resolvedCall.resultingDescriptor is SyntheticJavaPropertyDescriptor) {
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")
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.ReferencesToSyntheticJavaProperties)) {
context.trace.report(UNSUPPORTED_FEATURE.on(reportOn, LanguageFeature.ReferencesToSyntheticJavaProperties to context.languageVersionSettings))
} else if (!context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
context.trace.report(UNSUPPORTED_FEATURE.on(reportOn, LanguageFeature.NewInference to context.languageVersionSettings))
}
context.trace.report(diagnostic)
}
}
}
@@ -935,8 +935,6 @@ 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);
DiagnosticFactory0<PsiElement> ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE = DiagnosticFactory0.create(ERROR);
// Destructuring-declarations
@@ -1088,8 +1088,6 @@ 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");
MAP.put(ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE, "Adapted callable reference cannot be resolved against reflective types");
//Inline
@@ -1,3 +1,5 @@
// !LANGUAGE: -ReferencesToSyntheticJavaProperties
// FILE: Customer.java
public class Customer {
private String name;
@@ -1,3 +1,5 @@
// !LANGUAGE: -ReferencesToSyntheticJavaProperties
// FILE: Customer.java
public class Customer {
private String name;
@@ -16,4 +18,4 @@ public class Customer {
}
// FILE: test.kt
val customerName = Customer::<!UNSUPPORTED!>name<!>
val customerName = Customer::<!UNSUPPORTED_FEATURE!>name<!>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ReferencesToSyntheticJavaProperties
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
@@ -1,17 +0,0 @@
// !LANGUAGE: +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() {}
}
@@ -6,8 +6,8 @@
fun call(c: Any) {}
fun test() {
JavaClass::<!UNSUPPORTED!>foo<!>
call(JavaClass::<!UNSUPPORTED!>foo<!>)
JavaClass::<!UNSUPPORTED_FEATURE!>foo<!>
call(JavaClass::<!UNSUPPORTED_FEATURE!>foo<!>)
}
// FILE: JavaClass.java
@@ -31631,6 +31631,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.kt");
}
@Test
@TestMetadata("FullySupportedSyntheticJavaPropertyReference.kt")
public void testFullySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FullySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("GenericClass.kt")
public void testGenericClass() throws Exception {
@@ -31733,12 +31739,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.kt");
}
@Test
@TestMetadata("PartiallySupportedSyntheticJavaPropertyReference.kt")
public void testPartiallySupportedSyntheticJavaPropertyReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/PartiallySupportedSyntheticJavaPropertyReference.kt");
}
@Test
@TestMetadata("SetterHasHigherAccess.kt")
public void testSetterHasHigherAccess() throws Exception {