diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt index 14646602f84..86bfa8d6eea 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt @@ -29,13 +29,13 @@ } @R|NullableApi|() public open class B : R|A|, R|AInt| { - public open fun foo1(x: R|Enhanced for warning(kotlin/String?) kotlin/String!|): R|Enhanced for warning(kotlin/String?) kotlin/String!| + public open fun foo1(x: R|kotlin/String!|): R|kotlin/String!| @R|javax/annotation/Nonnull|() public open fun foo2(@R|javax/annotation/Nonnull|() x: R|@EnhancedNullability kotlin/String|): R|@EnhancedNullability kotlin/String| public open fun bar1(x: R|@EnhancedNullability kotlin/String?|): R|@EnhancedNullability kotlin/String?| - public open fun baz(x: R|@EnhancedNullability kotlin/String|): R|Enhanced for warning(kotlin/String?) kotlin/String!| + public open fun baz(x: R|@EnhancedNullability kotlin/String|): R|kotlin/String!| public constructor(): R|B| diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt index 86b215a0700..4aab1c4758f 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt @@ -891,7 +891,7 @@ private class EnhancementSignatureParts( get() = ((this as? ConeLookupTagBasedType)?.lookupTag as? ConeClassLikeLookupTag)?.classId?.asSingleFqName()?.toUnsafe() override val KotlinTypeMarker.enhancedForWarnings: KotlinTypeMarker? - get() = null // TODO: implement enhancement for warnings + get() = (this as ConeKotlinType).enhancedTypeForWarning override fun KotlinTypeMarker.isEqual(other: KotlinTypeMarker): Boolean = AbstractTypeChecker.equalTypes(session.typeContext, this, other) diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt index a1376c6e76f..49639eabe28 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt @@ -8,7 +8,9 @@ package org.jetbrains.kotlin.fir.java.enhancement import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration import org.jetbrains.kotlin.fir.languageVersionSettings +import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag import org.jetbrains.kotlin.fir.types.* @@ -160,17 +162,31 @@ private fun ConeLookupTagBasedType.enhanceInflexibleType( } var globalArgIndex = index + 1 - val enhancedArguments = typeArguments.map { arg -> - val argIndex = globalArgIndex.also { globalArgIndex += subtreeSizes[it] } - arg.type?.enhanceConeKotlinType(session, qualifiers, argIndex, subtreeSizes, convertErrorsToWarnings = convertNestedErrorsToWarnings) - ?.let { - when (arg.kind) { - ProjectionKind.IN -> ConeKotlinTypeProjectionIn(it) - ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(it) - ProjectionKind.STAR -> ConeStarProjection - ProjectionKind.INVARIANT -> it - } + val enhancedArguments = typeArguments.mapIndexed { currentArgLocalIndex, arg -> + val currentArgGlobalIndex = globalArgIndex.also { globalArgIndex += subtreeSizes[it] } + if (arg.type == null && qualifiers(currentArgGlobalIndex).nullability == NullabilityQualifier.FORCE_FLEXIBILITY) { + // Given `C`, unannotated `C` is `C`. + val typeParameters = (this.lookupTag.toSymbol(session)?.fir as? FirClassLikeDeclaration)?.typeParameters + if (typeParameters != null) { + val bound = typeParameters[currentArgLocalIndex].symbol.fir.bounds.first().coneType + return@mapIndexed ConeKotlinTypeProjectionOut( + ConeFlexibleType( + bound.lowerBoundIfFlexible().withNullability(ConeNullability.NOT_NULL, session.typeContext), + bound.upperBoundIfFlexible().withNullability(ConeNullability.NULLABLE, session.typeContext) + ) + ) } + } + arg.type?.enhanceConeKotlinType( + session, qualifiers, currentArgGlobalIndex, subtreeSizes, convertErrorsToWarnings = convertNestedErrorsToWarnings + )?.let { + when (arg.kind) { + ProjectionKind.IN -> ConeKotlinTypeProjectionIn(it) + ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(it) + ProjectionKind.STAR -> ConeStarProjection + ProjectionKind.INVARIANT -> it + } + } } val shouldAddAttribute = nullabilityFromQualifiers == NullabilityQualifier.NOT_NULL && !hasEnhancedNullability diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt deleted file mode 100644 index b5be33deeba..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt +++ /dev/null @@ -1,34 +0,0 @@ -// FILE: NullnessUnspecifiedTypeParameter.java -import org.jspecify.annotations.*; - -@NullMarked -public class NullnessUnspecifiedTypeParameter { - public void foo(T t) {} - - public void bar(Test s, T t) {} // t should not become not nullable -} - -// FILE: Test.java -public class Test {} - -// FILE: main.kt -// jspecify_nullness_mismatch -fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch - a1.foo(null) - a1.foo(1) - - a2.foo(null) - a2.foo(1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a1.bar(null, null) - // jspecify_nullness_mismatch - a1.bar(x, null) - a1.bar(x, 1) - - // jspecify_nullness_mismatch - a2.bar(null, null) - a2.bar(x, null) - a2.bar(x, 1) -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt index aad5c65b3ae..8dc05e40732 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.annotations.*; diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.fir.kt deleted file mode 100644 index ae0e41e2640..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// JSPECIFY_STATE: strict -// FILE: Box.java - -import org.jspecify.annotations.*; - -@NullMarked -public class Box { - public static Box make() { - return new Box<>(); - } -} - -// FILE: Util.java -public final class Util { - public Box boxId(Box box) { return box; } -} - -// FILE: a.kt -fun foo(u: Util) = - u.boxId(Box.make()) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.kt index 3016e74a14c..c3577c5bd39 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullMarkedWithStarType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: strict // FILE: Box.java diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt deleted file mode 100644 index 6313fc4f6c9..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// JSPECIFY_STATE: strict -// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode - -// FILE: J1.java -import org.jspecify.annotations.*; - -@NullMarked -public interface J1 { - T foo(); -} - -// FILE: J2.java -public interface J2 { - J1 bar(); -} - -// FILE: main.kt -fun baz(j2: J2): Any = j2.bar().foo() // Any..Any? diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt index 9b7032da0f6..2d98b53785c 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: strict // !LANGUAGE: +TypeEnhancementImprovementsInStrictMode diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.fir.kt deleted file mode 100644 index 6c416d2004a..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// JSPECIFY_STATE: warn -// FILE: Box.java - -import org.jspecify.annotations.*; - -@NullMarked -public class Box { - public static Box make() { - return new Box<>(); - } -} - -// FILE: Util.java -public final class Util { - public Box boxId(Box box) { return box; } -} - -// FILE: a.kt -fun foo(u: Util) = - u.boxId(Box.make()) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.kt index b402eb0f232..cc3ac57fac7 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullMarkedWithStarType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: warn // FILE: Box.java diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt deleted file mode 100644 index ea7fcb7f579..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt +++ /dev/null @@ -1,35 +0,0 @@ -// JSPECIFY_STATE: warn -// FILE: NullnessUnspecifiedTypeParameter.java -import org.jspecify.annotations.*; - -@NullMarked -public class NullnessUnspecifiedTypeParameter { - public void foo(T t) {} - - public void bar(Test s, T t) {} // t should not become not nullable -} - -// FILE: Test.java -public class Test {} - -// FILE: main.kt -// jspecify_nullness_mismatch -fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch - a1.foo(null) - a1.foo(1) - - a2.foo(null) - a2.foo(1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a1.bar(null, null) - // jspecify_nullness_mismatch - a1.bar(x, null) - a1.bar(x, 1) - - // jspecify_nullness_mismatch - a2.bar(null, null) - a2.bar(x, null) - a2.bar(x, 1) -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt index 0cf04e2b781..a9ca13c142b 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: warn // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.annotations.*; diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt index 8b1fe789cd3..be27c256d37 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt @@ -40,15 +40,18 @@ public class CKN extends C<@Nullable CK> {} // FILE: main.kt fun main(ak: AK, akn: AKN, bk: BK, ck: CK, ckn: CKN): Unit { ak.foo(ak) - ak.foo(null) + // jspecify_nullness_mismatch + ak.foo(null) akn.foo(null) // the corresponding warning/error is present on the Java side bk.foo(bk) - bk.foo(null) + // jspecify_nullness_mismatch + bk.foo(null) ck.foo(ck) - ck.foo(null) + // jspecify_nullness_mismatch + ck.foo(null) ckn.foo(null) // the corresponding warning/error is present on the Java side } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt index c40003cdce9..40f7802a060 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt @@ -23,19 +23,24 @@ public class Test {} // jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - a1.bar(null) + // jspecify_nullness_mismatch + a1.bar(null) a1.bar(x) a2.foo(null) - a2.bar(null) + // jspecify_nullness_mismatch + a2.bar(null) a2.bar(x) - b1.foo(null) - b1.bar(null) + // jspecify_nullness_mismatch + b1.foo(null) + // jspecify_nullness_mismatch + b1.bar(null) b1.bar(x) // jspecify_nullness_mismatch b2.foo(null) - b2.bar(null) + // jspecify_nullness_mismatch + b2.bar(null) b2.bar(x) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.fir.kt deleted file mode 100644 index 930bdf0bac8..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.fir.kt +++ /dev/null @@ -1,36 +0,0 @@ -// FILE: NullnessUnspecifiedTypeParameter.java -import org.jspecify.nullness.*; - -@NullMarked -public class NullnessUnspecifiedTypeParameter { - public void foo(T t) {} - - public void bar(Test s, T t) {} // t should not become not nullable -} - -// FILE: Test.java -public class Test {} - -// FILE: main.kt -// jspecify_nullness_mismatch -fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch - a1.foo(null) - a1.foo(1) - - // jspecify_nullness_mismatch - a2.foo(null) - a2.foo(1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a1.bar(null, null) - // jspecify_nullness_mismatch - a1.bar(x, null) - a1.bar(x, 1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a2.bar(null, null) - // jspecify_nullness_mismatch - a2.bar(x, null) - a2.bar(x, 1) -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.kt index 7b05a230ea9..8181702a4e9 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/default.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.nullness.*; diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.fir.kt deleted file mode 100644 index f78aaad678d..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// JSPECIFY_STATE: strict -// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode - -// FILE: J1.java -import org.jspecify.nullness.*; - -@NullMarked -public interface J1 { - T foo(); -} - -// FILE: J2.java -public interface J2 { - J1 bar(); -} - -// FILE: main.kt -fun baz(j2: J2): Any = j2.bar().foo() // Any..Any? diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.kt index 53881e2a111..52b0f9ac36a 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/strictMode/UnannotatedWildcard.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: strict // !LANGUAGE: +TypeEnhancementImprovementsInStrictMode diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.fir.kt deleted file mode 100644 index e36c47ac722..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.fir.kt +++ /dev/null @@ -1,37 +0,0 @@ -// JSPECIFY_STATE: warn -// FILE: NullnessUnspecifiedTypeParameter.java -import org.jspecify.nullness.*; - -@NullMarked -public class NullnessUnspecifiedTypeParameter { - public void foo(T t) {} - - public void bar(Test s, T t) {} // t should not become not nullable -} - -// FILE: Test.java -public class Test {} - -// FILE: main.kt -// jspecify_nullness_mismatch -fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch - a1.foo(null) - a1.foo(1) - - // jspecify_nullness_mismatch - a2.foo(null) - a2.foo(1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a1.bar(null, null) - // jspecify_nullness_mismatch - a1.bar(x, null) - a1.bar(x, 1) - - // jspecify_nullness_mismatch, jspecify_nullness_mismatch - a2.bar(null, null) - // jspecify_nullness_mismatch - a2.bar(x, null) - a2.bar(x, 1) -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.kt index a3154623f08..fb154eeb38e 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/NullnessUnspecifiedTypeParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // JSPECIFY_STATE: warn // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.nullness.*; diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/SelfType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/SelfType.fir.kt index a24dae1365e..ce78cab1543 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/SelfType.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/SelfType.fir.kt @@ -41,17 +41,17 @@ public class CKN extends C<@Nullable CK> {} fun main(ak: AK, akn: AKN, bk: BK, ck: CK, ckn: CKN): Unit { ak.foo(ak) // jspecify_nullness_mismatch - ak.foo(null) + ak.foo(null) akn.foo(null) // the corresponding warning/error is present on the Java side bk.foo(bk) // jspecify_nullness_mismatch - bk.foo(null) + bk.foo(null) ck.foo(ck) // jspecify_nullness_mismatch - ck.foo(null) + ck.foo(null) ckn.foo(null) // the corresponding warning/error is present on the Java side } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/TypeParameterBounds.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/TypeParameterBounds.fir.kt index ad09dacfb11..f20d372e6a4 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/TypeParameterBounds.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecifyOld/warnMode/TypeParameterBounds.fir.kt @@ -24,23 +24,23 @@ public class Test {} fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) // jspecify_nullness_mismatch - a1.bar(null) + a1.bar(null) a1.bar(x) a2.foo(null) // jspecify_nullness_mismatch - a2.bar(null) + a2.bar(null) a2.bar(x) // jspecify_nullness_mismatch - b1.foo(null) + b1.foo(null) // jspecify_nullness_mismatch - b1.bar(null) + b1.bar(null) b1.bar(x) // jspecify_nullness_mismatch b2.foo(null) // jspecify_nullness_mismatch - b2.bar(null) + b2.bar(null) b2.bar(x) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.fir.kt deleted file mode 100644 index afdbdfeabd8..00000000000 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.fir.kt +++ /dev/null @@ -1,152 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -// JSR305_GLOBAL_REPORT: warn - -// FILE: NonNullApi.java -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.METHOD, ElementType.PARAMETER, ElementType.FIELD}) -public @interface NonNullApi { -} - -// FILE: NullableApi.java -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.CheckForNull; -import javax.annotation.meta.TypeQualifierDefault; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@CheckForNull -@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) -public @interface NullableApi { -} - -// FILE: A.java -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -@NonNullApi -public class A { - public String foo1(String x) { return ""; } - public String foo2(String x) { return ""; } - public String foo3(String x) { return ""; } - - - @Nullable - public String bar1(@Nullable String x) { return ""; } - @Nullable - public String bar2(@Nullable String x) { return ""; } - - public String baz(@Nonnull String x) { return ""; } -} - -// FILE: AInt.java -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -@NonNullApi -public interface AInt { - public CharSequence foo1(String x); - public CharSequence foo2(String x); - public CharSequence foo3(String x); - - - @Nullable - public CharSequence bar1(@Nullable String x); - @Nullable - public CharSequence bar2(@Nullable String x); - - public CharSequence baz(@Nonnull String x); -} - - -// FILE: B.java -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -@NullableApi -public class B extends A implements AInt { - // conflicts - public String foo1(String x) { return ""; } - - // no conflicts - @Nonnull - public String foo2(@Nonnull String x) { return ""; } - - // fake override for foo3 shouldn't have any conflicts - - // no conflicts - public String bar1(String x) { return ""; } - - // conflicts - public String baz(String x) { return ""; } -} - -// FILE: C.java -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -@NonNullApi -public class C extends A implements AInt { - // no conflicts - public String foo1(String x) { return ""; } - - // no conflicts - public String foo2(@Nonnull String x) { return ""; } - - // fake override for foo3 shouldn't have any conflicts - - // no conflicts, covariant override - public String bar1(String x) { return ""; } - // no conflicts - @Nullable - public String bar2(@Nullable String x) { return ""; } - - // no conflicts - public String baz(String x) { return ""; } -} - -// FILE: main.kt -fun main(a: A, b: B, c: C) { - a.foo1(null).length - a.foo2(null).length - a.foo3(null).length - a.bar1(null).length - a.bar2(null).length - a.baz(null).length - - b.foo1(null).length - b.foo1(null)?.length - b.foo2(null).length - b.foo3(null).length - b.bar1(null).length - b.bar2(null).length - b.baz(null).length - b.baz(null)?.length - - c.foo1(null).length - c.foo2(null).length - c.foo3(null).length - c.bar1(null).length - c.bar1(null)?.length - c.bar2(null).length - c.baz(null).length -} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt index d7197d6eb90..a9012b10f60 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305/nullabilityWarnings/typeQualifierDefault/nullabilityFromOverridden.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER // JSR305_GLOBAL_REPORT: warn