Don't ignore Java nullability annotations without target and unresolved when nullability qualifiers are extracted, with enabled type enhancement improvements
^KT-47276 Fixed
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
|||||||
|
// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
// JSR305_GLOBAL_REPORT: strict
|
||||||
|
|
||||||
|
// FILE: test/NonNullApi.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
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/A.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class A {
|
||||||
|
@Nullable
|
||||||
|
public String bar1() { return ""; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
import test.A
|
||||||
|
|
||||||
|
class Inv<T>(x: T)
|
||||||
|
|
||||||
|
fun foo(x: Inv<String?>) { }
|
||||||
|
|
||||||
|
fun main(a: A) {
|
||||||
|
val x = <!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.String?>")!>Inv(a.bar1())<!>
|
||||||
|
foo(x)
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(/*0*/ x: Inv<kotlin.String?>): kotlin.Unit
|
||||||
|
public fun main(/*0*/ a: test.A): kotlin.Unit
|
||||||
|
|
||||||
|
public final class Inv</*0*/ T> {
|
||||||
|
public constructor Inv</*0*/ T>(/*0*/ x: T)
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
package test {
|
||||||
|
|
||||||
|
public open class A {
|
||||||
|
public constructor A()
|
||||||
|
@javax.annotation.Nullable public open fun bar1(): kotlin.String?
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.annotation.Target(allowedTargets = {}) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @kotlin.annotation.MustBeDocumented @javax.annotation.Nonnull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER, ElementType.PACKAGE}) public final annotation class NonNullApi : kotlin.Annotation {
|
||||||
|
public constructor NonNullApi()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -101,6 +101,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("dontIgnoreAnnotationsWithoutTarget.kt")
|
||||||
|
public void testDontIgnoreAnnotationsWithoutTarget() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/dontIgnoreAnnotationsWithoutTarget.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nonNullNever.kt")
|
@TestMetadata("nonNullNever.kt")
|
||||||
public void testNonNullNever() throws Exception {
|
public void testNonNullNever() throws Exception {
|
||||||
|
|||||||
+6
@@ -101,6 +101,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("dontIgnoreAnnotationsWithoutTarget.kt")
|
||||||
|
public void testDontIgnoreAnnotationsWithoutTarget() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/dontIgnoreAnnotationsWithoutTarget.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nonNullNever.kt")
|
@TestMetadata("nonNullNever.kt")
|
||||||
public void testNonNullNever() throws Exception {
|
public void testNonNullNever() throws Exception {
|
||||||
|
|||||||
+6
@@ -101,6 +101,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("dontIgnoreAnnotationsWithoutTarget.kt")
|
||||||
|
public void testDontIgnoreAnnotationsWithoutTarget() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/dontIgnoreAnnotationsWithoutTarget.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("nonNullNever.kt")
|
@TestMetadata("nonNullNever.kt")
|
||||||
public void testNonNullNever() throws Exception {
|
public void testNonNullNever() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -332,7 +332,8 @@ class SignatureEnhancement(
|
|||||||
val composedAnnotation =
|
val composedAnnotation =
|
||||||
if (isHeadTypeConstructor && typeContainer != null && typeContainer !is TypeParameterDescriptor && areImprovementsInStrictMode) {
|
if (isHeadTypeConstructor && typeContainer != null && typeContainer !is TypeParameterDescriptor && areImprovementsInStrictMode) {
|
||||||
val filteredContainerAnnotations = typeContainer.annotations.filter {
|
val filteredContainerAnnotations = typeContainer.annotations.filter {
|
||||||
val (_, targets) = annotationTypeQualifierResolver.resolveAnnotation(it) ?: return@filter false
|
val (_, targets) = annotationTypeQualifierResolver.resolveAnnotation(it)
|
||||||
|
?: return@filter true // don't exclude annotations without specified target or unresolved
|
||||||
/*
|
/*
|
||||||
* We don't apply container type use annotations to avoid double applying them like with arrays:
|
* We don't apply container type use annotations to avoid double applying them like with arrays:
|
||||||
* @NotNull Integer [] f15();
|
* @NotNull Integer [] f15();
|
||||||
|
|||||||
Reference in New Issue
Block a user