[FIR] Fix duplicate WRONG_NULLABILITY_FOR_JAVA_OVERRIDE
Also, the test shows a missing warning in K1 which is present in K2. #KT-63600 Fixed #KT-63599 #KT-63745 #KT-63746
This commit is contained in:
committed by
Space Team
parent
54c2339dfb
commit
4882ac6599
+6
@@ -240,6 +240,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaTestGenerated extend
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
+6
@@ -298,6 +298,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingT
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
+6
@@ -298,6 +298,12 @@ public class FirPsiOldFrontendForeignAnnotationsSourceJavaTestGenerated extends
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
+7
-4
@@ -35,6 +35,7 @@ object FirOverrideJavaNullabilityWarningChecker : FirAbstractOverrideChecker() {
|
|||||||
|
|
||||||
for (member in declaration.declarations) {
|
for (member in declaration.declarations) {
|
||||||
var anyBaseEnhanced = false
|
var anyBaseEnhanced = false
|
||||||
|
var anyReported = false
|
||||||
|
|
||||||
if (member is FirSimpleFunction) {
|
if (member is FirSimpleFunction) {
|
||||||
val enhancedOverrides = scope
|
val enhancedOverrides = scope
|
||||||
@@ -44,7 +45,8 @@ object FirOverrideJavaNullabilityWarningChecker : FirAbstractOverrideChecker() {
|
|||||||
val substitutedBase = it.fir.substituteOrNull(substitutor, context) ?: return@map it
|
val substitutedBase = it.fir.substituteOrNull(substitutor, context) ?: return@map it
|
||||||
anyBaseEnhanced = true
|
anyBaseEnhanced = true
|
||||||
|
|
||||||
if (!context.session.firOverrideChecker.isOverriddenFunction(member, substitutedBase)) {
|
if (!anyReported && !context.session.firOverrideChecker.isOverriddenFunction(member, substitutedBase)) {
|
||||||
|
anyReported = true
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
member.source,
|
member.source,
|
||||||
FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE,
|
FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE,
|
||||||
@@ -57,7 +59,7 @@ object FirOverrideJavaNullabilityWarningChecker : FirAbstractOverrideChecker() {
|
|||||||
substitutedBase.symbol
|
substitutedBase.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anyBaseEnhanced) {
|
if (anyBaseEnhanced && !anyReported) {
|
||||||
member.symbol.checkReturnType(enhancedOverrides, typeCheckerState, context)?.let {
|
member.symbol.checkReturnType(enhancedOverrides, typeCheckerState, context)?.let {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
member.source, FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE, member.symbol, it, context
|
member.source, FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE, member.symbol, it, context
|
||||||
@@ -72,7 +74,8 @@ object FirOverrideJavaNullabilityWarningChecker : FirAbstractOverrideChecker() {
|
|||||||
val substitutedBase = it.fir.substituteOrNull(substitutor, context) ?: return@map it
|
val substitutedBase = it.fir.substituteOrNull(substitutor, context) ?: return@map it
|
||||||
anyBaseEnhanced = true
|
anyBaseEnhanced = true
|
||||||
|
|
||||||
if (!context.session.firOverrideChecker.isOverriddenProperty(member, substitutedBase)) {
|
if (!anyReported && !context.session.firOverrideChecker.isOverriddenProperty(member, substitutedBase)) {
|
||||||
|
anyReported = true
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
member.source,
|
member.source,
|
||||||
FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE,
|
FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE,
|
||||||
@@ -85,7 +88,7 @@ object FirOverrideJavaNullabilityWarningChecker : FirAbstractOverrideChecker() {
|
|||||||
substitutedBase.symbol
|
substitutedBase.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anyBaseEnhanced) {
|
if (anyBaseEnhanced && !anyReported) {
|
||||||
member.symbol.checkReturnType(enhancedOverrides, typeCheckerState, context)?.let {
|
member.symbol.checkReturnType(enhancedOverrides, typeCheckerState, context)?.let {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
member.source, FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE, member.symbol, it, context
|
member.source, FirJvmErrors.WRONG_NULLABILITY_FOR_JAVA_OVERRIDE, member.symbol, it, context
|
||||||
|
|||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||||
|
// JSR305_GLOBAL_REPORT: warn
|
||||||
|
|
||||||
|
// FILE: test/NonNullApi.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.meta.TypeQualifierDefault;
|
||||||
|
|
||||||
|
@Target(ElementType.PACKAGE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Nonnull
|
||||||
|
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.PACKAGE})
|
||||||
|
public @interface NonNullApi {
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test/package-info.java
|
||||||
|
@NonNullApi
|
||||||
|
package test;
|
||||||
|
|
||||||
|
// FILE: test/Provider.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import javax.annotation.*;
|
||||||
|
|
||||||
|
public interface Provider<T> {
|
||||||
|
T get();
|
||||||
|
@Nullable T getNullable();
|
||||||
|
void set(T x);
|
||||||
|
void setNullable(@Nullable T x);
|
||||||
|
|
||||||
|
T getSet(T x);
|
||||||
|
@Nullable T getSetNullable(@Nullable T x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test/I.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import javax.annotation.*;
|
||||||
|
|
||||||
|
public interface I<T> {
|
||||||
|
T get();
|
||||||
|
void set(T x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
package test;
|
||||||
|
|
||||||
|
abstract class Multiple<T> : Provider<T>, I<T> {
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun get(): T = null!!
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun set(x: T) {} // Missing warning in K1, K2 get's this right
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class A<T> : Provider<T> {
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun get(): T = null!!
|
||||||
|
override fun getNullable(): T = null!!
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun set(x: T) {} // Missing warning in K1, K2 get's this right
|
||||||
|
<!NOTHING_TO_OVERRIDE!>override<!> fun setNullable(x: T) {}
|
||||||
|
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun getSet(x: T): T = x
|
||||||
|
<!NOTHING_TO_OVERRIDE!>override<!> fun getSetNullable(x: T): T = x
|
||||||
|
}
|
||||||
Vendored
+64
@@ -0,0 +1,64 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||||
|
// JSR305_GLOBAL_REPORT: warn
|
||||||
|
|
||||||
|
// FILE: test/NonNullApi.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.meta.TypeQualifierDefault;
|
||||||
|
|
||||||
|
@Target(ElementType.PACKAGE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Nonnull
|
||||||
|
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.PACKAGE})
|
||||||
|
public @interface NonNullApi {
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test/package-info.java
|
||||||
|
@NonNullApi
|
||||||
|
package test;
|
||||||
|
|
||||||
|
// FILE: test/Provider.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import javax.annotation.*;
|
||||||
|
|
||||||
|
public interface Provider<T> {
|
||||||
|
T get();
|
||||||
|
@Nullable T getNullable();
|
||||||
|
void set(T x);
|
||||||
|
void setNullable(@Nullable T x);
|
||||||
|
|
||||||
|
T getSet(T x);
|
||||||
|
@Nullable T getSetNullable(@Nullable T x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test/I.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import javax.annotation.*;
|
||||||
|
|
||||||
|
public interface I<T> {
|
||||||
|
T get();
|
||||||
|
void set(T x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
package test;
|
||||||
|
|
||||||
|
abstract class Multiple<T> : Provider<T>, I<T> {
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun get(): T = null!!
|
||||||
|
override fun set(x: T) {} // Missing warning in K1, K2 get's this right
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class A<T> : Provider<T> {
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun get(): T = null!!
|
||||||
|
override fun getNullable(): T = null!!
|
||||||
|
override fun set(x: T) {} // Missing warning in K1, K2 get's this right
|
||||||
|
<!NOTHING_TO_OVERRIDE!>override<!> fun setNullable(x: T) {}
|
||||||
|
|
||||||
|
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun getSet(x: T): T = x
|
||||||
|
<!NOTHING_TO_OVERRIDE!>override<!> fun getSetNullable(x: T): T = x
|
||||||
|
}
|
||||||
+6
@@ -240,6 +240,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
+6
@@ -298,6 +298,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
+6
@@ -298,6 +298,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("override.kt")
|
||||||
|
public void testOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/override.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("safeCalls.kt")
|
@TestMetadata("safeCalls.kt")
|
||||||
public void testSafeCalls() throws Exception {
|
public void testSafeCalls() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user