Fix exception when reporting WRONG_TYPE_PARAMETER_NULLABILITY_FOR_JAVA_OVERRIDE
^KT-51979 Fixed
This commit is contained in:
+6
@@ -18717,6 +18717,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/constantStaticStringField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noOverrideKeyword.kt")
|
||||
public void testNoOverrideKeyword() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/noOverrideKeyword.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullTypeParameterWithKotlinNullable.kt")
|
||||
public void testNotNullTypeParameterWithKotlinNullable() throws Exception {
|
||||
|
||||
+6
@@ -18717,6 +18717,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/constantStaticStringField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noOverrideKeyword.kt")
|
||||
public void testNoOverrideKeyword() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/noOverrideKeyword.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullTypeParameterWithKotlinNullable.kt")
|
||||
public void testNotNullTypeParameterWithKotlinNullable() throws Exception {
|
||||
|
||||
+6
@@ -18717,6 +18717,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/constantStaticStringField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noOverrideKeyword.kt")
|
||||
public void testNoOverrideKeyword() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/noOverrideKeyword.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullTypeParameterWithKotlinNullable.kt")
|
||||
public void testNotNullTypeParameterWithKotlinNullable() throws Exception {
|
||||
|
||||
+5
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
@@ -30,6 +31,10 @@ object JavaOverrideWithWrongNullabilityOverrideChecker : DeclarationChecker {
|
||||
if (descriptor !is CallableMemberDescriptor) return
|
||||
if (descriptor.overriddenDescriptors.isEmpty()) return
|
||||
|
||||
val modifierList = declaration.modifierList
|
||||
val hasOverrideNode = modifierList != null && modifierList.hasModifier(KtTokens.OVERRIDE_KEYWORD)
|
||||
if (!hasOverrideNode) return
|
||||
|
||||
val containingClass = descriptor.containingDeclaration as? ClassDescriptor ?: return
|
||||
|
||||
for (overriddenDescriptor in descriptor.overriddenDescriptors) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// !SKIP_JAVAC
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: -ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
|
||||
// FILE: JavaInterface.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface JavaInterface<V> {
|
||||
void interfaceMethod(@NotNull V value);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
interface KotlinInterface<X> : JavaInterface<X> {
|
||||
override <!SYNTAX!><<!><!SYNTAX!>T<!><!SYNTAX!>><!> fun interfaceMethod(x: X)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// !SKIP_JAVAC
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: -ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
|
||||
// FILE: JavaInterface.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface JavaInterface<V> {
|
||||
void interfaceMethod(@NotNull V value);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
interface KotlinInterface<X> : JavaInterface<X> {
|
||||
override <!SYNTAX!><<!><!SYNTAX!>T<!><!SYNTAX!>><!> fun <!VIRTUAL_MEMBER_HIDDEN!>interfaceMethod<!>(x: X)
|
||||
}
|
||||
Generated
+6
@@ -18723,6 +18723,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/constantStaticStringField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noOverrideKeyword.kt")
|
||||
public void testNoOverrideKeyword() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/types/noOverrideKeyword.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullTypeParameterWithKotlinNullable.kt")
|
||||
public void testNotNullTypeParameterWithKotlinNullable() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user