FE: force flexibility on unannotated ?
TODO: unify this code with FIR #KT-48515 Fixed
This commit is contained in:
+12
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+12
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+12
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// JSPECIFY_STATE: strict
|
||||||
|
// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode
|
||||||
|
|
||||||
|
// FILE: J1.java
|
||||||
|
import org.jspecify.nullness.*;
|
||||||
|
|
||||||
|
@NullMarked
|
||||||
|
public interface J1<T extends @Nullable Object> {
|
||||||
|
T foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: J2.java
|
||||||
|
public interface J2 {
|
||||||
|
J1<?> bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
fun baz(j2: J2): Any = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>j2.bar().foo()<!> // Any..Any?
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// JSPECIFY_STATE: strict
|
||||||
|
// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode
|
||||||
|
|
||||||
|
// FILE: J1.java
|
||||||
|
import org.jspecify.nullness.*;
|
||||||
|
|
||||||
|
@NullMarked
|
||||||
|
public interface J1<T extends @Nullable Object> {
|
||||||
|
T foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: J2.java
|
||||||
|
public interface J2 {
|
||||||
|
J1<?> bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
fun baz(j2: J2): Any = j2.bar().foo() // Any..Any?
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun baz(/*0*/ j2: J2): kotlin.Any
|
||||||
|
|
||||||
|
@org.jspecify.nullness.NullMarked public interface J1</*0*/ T> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract fun foo(): T
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface J2 {
|
||||||
|
public abstract fun bar(): J1<out @org.jspecify.nullness.Nullable kotlin.Any!>!
|
||||||
|
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
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// JSPECIFY_STATE: warn
|
||||||
|
// FILE: J1.java
|
||||||
|
import org.jspecify.nullness.*;
|
||||||
|
|
||||||
|
@NullMarked
|
||||||
|
public interface J1<T extends @Nullable Object> {
|
||||||
|
T foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: J2.java
|
||||||
|
public interface J2 {
|
||||||
|
J1<?> bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
fun baz(j2: J2): Any = j2.bar().foo() // Any..Any?
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun baz(/*0*/ j2: J2): kotlin.Any
|
||||||
|
|
||||||
|
@org.jspecify.nullness.NullMarked public interface J1</*0*/ T : @org.jspecify.nullness.Nullable kotlin.Any!> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract fun foo(): T!
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface J2 {
|
||||||
|
public abstract fun bar(): J1<out @org.jspecify.nullness.Nullable kotlin.Any!>!
|
||||||
|
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
|
||||||
|
}
|
||||||
+12
@@ -714,6 +714,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+12
@@ -714,6 +714,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+12
@@ -714,6 +714,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
@@ -796,6 +802,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
|||||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("UnannotatedWildcard.kt")
|
||||||
|
public void testUnannotatedWildcard() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/UnannotatedWildcard.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WildcardsWithDefault.kt")
|
@TestMetadata("WildcardsWithDefault.kt")
|
||||||
public void testWildcardsWithDefault() throws Exception {
|
public void testWildcardsWithDefault() throws Exception {
|
||||||
|
|||||||
+10
@@ -119,6 +119,16 @@ class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings
|
|||||||
val enhanced = when {
|
val enhanced = when {
|
||||||
!shouldEnhanceArguments -> Result(null, 0)
|
!shouldEnhanceArguments -> Result(null, 0)
|
||||||
!arg.isStarProjection -> arg.type.unwrap().enhancePossiblyFlexible(qualifiers, globalArgIndex, isSuperTypesEnhancement)
|
!arg.isStarProjection -> arg.type.unwrap().enhancePossiblyFlexible(qualifiers, globalArgIndex, isSuperTypesEnhancement)
|
||||||
|
qualifiers(globalArgIndex).nullability == FORCE_FLEXIBILITY ->
|
||||||
|
arg.type.unwrap().let {
|
||||||
|
// Given `C<T extends @Nullable V>`, unannotated `C<?>` is `C<out (V..V?)>`.
|
||||||
|
Result(
|
||||||
|
KotlinTypeFactory.flexibleType(
|
||||||
|
it.lowerIfFlexible().makeNullableAsSpecified(false),
|
||||||
|
it.upperIfFlexible().makeNullableAsSpecified(true)
|
||||||
|
), 1
|
||||||
|
)
|
||||||
|
}
|
||||||
else -> Result(null, 1)
|
else -> Result(null, 1)
|
||||||
}
|
}
|
||||||
globalArgIndex += enhanced.subtreeSize
|
globalArgIndex += enhanced.subtreeSize
|
||||||
|
|||||||
Reference in New Issue
Block a user