Skip to content

Commit

Permalink
Fix exception when reporting WRONG_TYPE_PARAMETER_NULLABILITY_FOR_JAV…
Browse files Browse the repository at this point in the history
…A_OVERRIDE

^KT-51979 Fixed
  • Loading branch information
dzharkov authored and Space committed Apr 18, 2022
1 parent 2f4afe0 commit 3ac8d95
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
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
Expand All @@ -27,6 +28,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 14 additions & 0 deletions compiler/testData/diagnostics/tests/j+k/types/noOverrideKeyword.kt
Original file line number Diff line number Diff line change
@@ -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)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ac8d95

Please sign in to comment.