From 644391a8e0c0fc4928d4804f2d460b4bf21576a1 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Mon, 13 Mar 2023 18:14:06 +0100 Subject: [PATCH] K2: Fix Java enhancement when jsr305.jar is not in classpath In that case, when loading Java, we just remember the name of `@Nonnull` argument (javax.annotation.meta.When), and then use it during enhancement ^KT-56656 Fixed --- .../AbstractAnnotationDeserializer.kt | 9 +-- .../FirAnnotationTypeQualifierResolver.kt | 14 +++- .../kotlin/fir/java/javaAnnotationsMapping.kt | 24 ++++-- .../defaultAnnotationAppliedToType.fir.kt | 77 ------------------ .../jsr305/defaultAnnotationAppliedToType.kt | 1 + ...otationAppliedToTypeForCompiledJava.fir.kt | 67 ---------------- ...tAnnotationAppliedToTypeForCompiledJava.kt | 1 + .../jsr305/springNullableWithTypeUse.fir.kt | 79 ------------------- .../jsr305/springNullableWithTypeUse.kt | 1 + .../java8Tests/jsr305/typeArguments.fir.kt | 12 +-- .../jsr305/typeUseVsMethodConflict.fir.kt | 77 ------------------ .../jsr305/typeUseVsMethodConflict.kt | 1 + ...rrideOfMethodWithParametricNullness.fir.kt | 56 ------------- .../overrideOfMethodWithParametricNullness.kt | 1 + 14 files changed, 46 insertions(+), 374 deletions(-) delete mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.fir.kt delete mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.fir.kt delete mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.fir.kt delete mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.fir.kt delete mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.fir.kt diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt index fff4cad0c9a..168392138c0 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt @@ -10,11 +10,9 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.collectEnumEntries -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.* -import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference +import org.jetbrains.kotlin.fir.references.builder.buildFromMissingDependenciesNamedReference import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.defaultType @@ -285,9 +283,8 @@ abstract class AbstractAnnotationDeserializer( name = entryName resolvedSymbol = it.symbol } - } ?: buildErrorNamedReference { - diagnostic = - ConeSimpleDiagnostic("Strange deserialized enum value: $classId.$entryName", DiagnosticKind.DeserializationError) + } ?: buildFromMissingDependenciesNamedReference { + name = entryName } if (enumEntrySymbol != null) { typeRef = enumEntrySymbol.returnTypeRef diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/FirAnnotationTypeQualifierResolver.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/FirAnnotationTypeQualifierResolver.kt index f36015ce380..e211131f0e9 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/FirAnnotationTypeQualifierResolver.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/FirAnnotationTypeQualifierResolver.kt @@ -12,8 +12,11 @@ import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack import org.jetbrains.kotlin.fir.java.convertAnnotationsToFir import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass +import org.jetbrains.kotlin.fir.references.FirFromMissingDependenciesNamedReference +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.toSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.load.java.AbstractAnnotationTypeQualifierResolver import org.jetbrains.kotlin.load.java.JavaModuleAnnotationsProvider import org.jetbrains.kotlin.load.java.JavaTypeEnhancementState @@ -48,7 +51,16 @@ class FirAnnotationTypeQualifierResolver( when (this) { is FirArrayOfCall -> arguments.flatMap { it.toEnumNames() } is FirVarargArgumentsExpression -> arguments.flatMap { it.toEnumNames() } - else -> listOfNotNull(toResolvedCallableSymbol()?.callableId?.callableName?.asString()) + else -> { + val name = when (val reference = toReference()) { + is FirResolvedNamedReference -> + (reference.resolvedSymbol as? FirCallableSymbol<*>)?.callableId?.callableName?.asString() + is FirFromMissingDependenciesNamedReference -> reference.name.asString() + else -> null + } + + listOfNotNull(name) + } } fun extractDefaultQualifiers(firClass: FirRegularClass): JavaTypeQualifiersByElementType? { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt index c49abf1d0f0..dbbab706b93 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt @@ -13,10 +13,15 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind -import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression +import org.jetbrains.kotlin.fir.expressions.buildUnaryArgumentList import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameter +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference +import org.jetbrains.kotlin.fir.references.builder.buildFromMissingDependenciesNamedReference import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.bindSymbolToLookupTag import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedReferenceError @@ -133,7 +138,7 @@ private val JAVA_TARGETS_TO_KOTLIN = mapOf( private fun buildEnumCall(session: FirSession, classId: ClassId?, entryName: Name?): FirPropertyAccessExpression { return buildPropertyAccessExpression { - val calleeReference = if (classId != null && entryName != null) { + val resolvedCalleeReference: FirResolvedNamedReference? = if (classId != null && entryName != null) { session.symbolProvider.getClassDeclaredPropertySymbols(classId, entryName) .firstOrNull()?.let { propertySymbol -> buildResolvedNamedReference { @@ -144,9 +149,18 @@ private fun buildEnumCall(session: FirSession, classId: ClassId?, entryName: Nam } else { null } - this.calleeReference = calleeReference ?: buildErrorNamedReference { - diagnostic = ConeSimpleDiagnostic("Strange Java enum value: $classId.$entryName", DiagnosticKind.Java) - } + + this.calleeReference = + resolvedCalleeReference + // if we haven't found the containing class for the entry in the classpath, let's just remember its name, so we could use it, + // e.g. during Java enhancement + ?: entryName?.let { + buildFromMissingDependenciesNamedReference { + name = entryName + } + } ?: buildErrorNamedReference { + diagnostic = ConeSimpleDiagnostic("Enum entry name is null in Java for $classId", DiagnosticKind.Java) + } if (classId != null) { this.typeRef = buildResolvedTypeRef { diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.fir.kt deleted file mode 100644 index c5437e20aba..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.fir.kt +++ /dev/null @@ -1,77 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// SKIP_JAVAC -// SOURCE_RETENTION_ANNOTATIONS -// JSR305_GLOBAL_REPORT: strict - -// FILE: spr/NonNullApi.java -package spr; - -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.TYPE, ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NonNullApi { -} - -// FILE: spr/NullableApi.java -package spr; - -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; -import javax.annotation.meta.When; - -@Target({ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull(when = When.MAYBE) -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NullableApi { -} - -// FILE: A.java -import spr.*; -import java.util.*; - -@NonNullApi -public class A { - public String foo(String x) { return ""; } - public @NullableApi String bar(@NullableApi String y) { return ""; } - public @NullableApi List baz1() { return null; } - public List<@NullableApi String> baz2() { return null; } - public @NullableApi List<@NonNullApi String> baz3() { return null; } -} - -// FILE: main.kt -fun main(a: A) { - a.foo("").length - a.foo(null)?.length - - a.bar("").length - a.bar(null)?.length - - a.baz1().get(0).length - a.baz1()!!.get(0).length - a.baz1()!!.get(0)?.length - - a.baz2().get(0).length - a.baz2()!!.get(0).length - a.baz2()!!.get(0)?.length - - a.baz3().get(0).length - a.baz3()!!.get(0).length - a.baz3()!!.get(0)?.length -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.kt index 979dfdc53fa..09ea5f6e25a 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // SKIP_JAVAC // SOURCE_RETENTION_ANNOTATIONS diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.fir.kt deleted file mode 100644 index 19e8cbed09f..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.fir.kt +++ /dev/null @@ -1,67 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// SKIP_JAVAC -// SOURCE_RETENTION_ANNOTATIONS -// JSR305_GLOBAL_REPORT: strict - -// FILE: spr/NonNullApi.java -package spr; - -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.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NonNullApi { -} - -// FILE: spr/NullableApi.java -package spr; - -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; -import javax.annotation.meta.When; - -@Target({ElementType.TYPE, ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull(when = When.MAYBE) -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NullableApi { -} - -// FILE: A.java -import spr.*; -import java.util.*; - -@NonNullApi -public class A { - public String foo(String x) { return ""; } - public @NullableApi String bar(@NullableApi String y) { return ""; } - public @NullableApi List baz1() { return null; } -} - -// FILE: main.kt -fun main(a: A) { - a.foo("").length - a.foo(null)?.length - - a.bar("").length - a.bar(null)?.length - - a.baz1().get(0).length - a.baz1()!!.get(0).length - a.baz1()!!.get(0)?.length -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.kt index 34ef4c49f09..9535ff5a2a6 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/defaultAnnotationAppliedToTypeForCompiledJava.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // SKIP_JAVAC // SOURCE_RETENTION_ANNOTATIONS diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.fir.kt deleted file mode 100644 index c71a03bfae0..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.fir.kt +++ /dev/null @@ -1,79 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// JSR305_GLOBAL_REPORT: strict - -// FILE: spr/Nullable.java -package spr; - -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.TypeQualifierNickname; -import javax.annotation.meta.When; - -@Target({ElementType.METHOD, ElementType.PARAMETER}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull(when = When.MAYBE) -@TypeQualifierNickname -public @interface Nullable { -} - -// FILE: spr/NonNullApi.java -package spr; - -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.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NonNullApi { -} - -// FILE: A.java -import spr.*; - -@NonNullApi -public class A { - public String field = null; - - public String foo(String x, @Nullable CharSequence y) { - return ""; - } - - public String bar() { - return ""; - } - - @Nullable - public java.util.List baz() { - return null; - } -} - -// FILE: main.kt -fun main(a: A) { - a.foo("", null)?.length - a.foo("", null).length - a.foo(null, "").length - - a.bar().length - a.bar()!!.length - - a.field?.length - a.field.length - - a.baz().get(0) - a.baz()!!.get(0).get(0) - a.baz()!!.get(0)?.get(0) -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.kt index 79296525360..6ea82cd5920 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/springNullableWithTypeUse.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // JSR305_GLOBAL_REPORT: strict diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeArguments.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeArguments.fir.kt index fdc1e2eaca0..abf9bd50e90 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeArguments.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeArguments.fir.kt @@ -78,15 +78,15 @@ import test.L fun main(a: test.A, l: L, Int?>, l1: L, Int>) { a.foo(l) a.foo(l as L, Int>) - a.foo(l as L, Int?>) + a.foo(l as L, Int?>) a.bar(l1) - a.bar(l1 as L, Int?>) + a.bar(l1 as L, Int?>) a.baz1().t().containsKey("") - a.baz1().t().containsKey(null) + a.baz1().t().containsKey(null) a.baz1().t().containsValue(1) - a.baz1().t().containsValue(null) + a.baz1().t().containsValue(null) a.baz1().s().hashCode() a.baz1().setT(l.t()) @@ -100,8 +100,8 @@ fun main(a: test.A, l: L, Int?>, l1: L, Int>) a.baz2().s().hashCode() a.baz3().t().containsKey("") - a.baz3().t().containsKey(null) + a.baz3().t().containsKey(null) a.baz3().t().containsValue(1) - a.baz3().t().containsValue(null) + a.baz3().t().containsValue(null) a.baz3().s().hashCode() } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.fir.kt deleted file mode 100644 index c1f2bfbd0d2..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.fir.kt +++ /dev/null @@ -1,77 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// SKIP_JAVAC -// SOURCE_RETENTION_ANNOTATIONS -// JSR305_GLOBAL_REPORT: strict - -// FILE: spr/NonNullApi.java -package spr; - -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.TYPE, ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull -@TypeQualifierDefault({ElementType.TYPE_USE, ElementType.METHOD}) -public @interface NonNullApi { -} - -// FILE: spr/NullableApi.java -package spr; - -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; -import javax.annotation.meta.When; - -@Target({ElementType.TYPE_USE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Nonnull(when = When.MAYBE) -@TypeQualifierDefault({ElementType.TYPE_USE}) -public @interface NullableApi { -} - -// FILE: A.java -import spr.*; -import java.util.*; - -@NonNullApi -public class A { - public String foo(String x) { return ""; } - public @NullableApi String bar(@NullableApi String y) { return ""; } - public @NullableApi List baz1() { return null; } - public List<@NullableApi String> baz2() { return null; } - public @NullableApi List<@NonNullApi String> baz3() { return null; } -} - -// FILE: main.kt -fun main(a: A) { - a.foo("").length - a.foo(null)?.length - - a.bar("").length - a.bar(null)?.length - - a.baz1().get(0).length - a.baz1()!!.get(0).length - a.baz1()!!.get(0)?.length - - a.baz2().get(0).length - a.baz2()!!.get(0).length - a.baz2()!!.get(0)?.length - - a.baz3().get(0).length - a.baz3()!!.get(0).length - a.baz3()!!.get(0)?.length -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.kt index a18cdcbf352..a948cfa9c06 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jsr305/typeUseVsMethodConflict.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // SKIP_JAVAC // SOURCE_RETENTION_ANNOTATIONS diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.fir.kt deleted file mode 100644 index 91737436753..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.fir.kt +++ /dev/null @@ -1,56 +0,0 @@ -// FULL_JDK -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// ISSUE: KT-56656 - -// FILE: ParametricNullness.java -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -@Target({FIELD, METHOD, PARAMETER}) -@javax.annotation.meta.TypeQualifierNickname -@javax.annotation.Nonnull(when = javax.annotation.meta.When.UNKNOWN) -@interface ParametricNullness {} - -// FILE: ElementTypesAreNonnullByDefault.java -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import javax.annotation.Nonnull; -import javax.annotation.meta.TypeQualifierDefault; - -/** - * Marks all "top-level" types as non-null in a way that is recognized by Kotlin. Note that this - * unfortunately includes type-variable usages, so we also provide {@link ParametricNullness} to - * "undo" it as best we can. - */ -@Retention(RUNTIME) -@Target(TYPE) -@TypeQualifierDefault({FIELD, METHOD, PARAMETER}) -@Nonnull -@interface ElementTypesAreNonnullByDefault {} - -// FILE: MyFunction.java -import javax.annotation.CheckForNull; -import org.checkerframework.checker.nullness.qual.Nullable; - -@ElementTypesAreNonnullByDefault -public interface MyFunction extends java.util.function.Function { - @Override - @ParametricNullness - T apply (@ParametricNullness F input); -} - -// FILE: main.kt - -class A : MyFunction { - override fun apply(x: String?): String? = "" -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.kt index a1193e9cb98..5c4d8fcd6be 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/overrideOfMethodWithParametricNullness.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FULL_JDK // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // ISSUE: KT-56656