FE: force flexibility on unannotated ?

TODO: unify this code with FIR

 #KT-48515 Fixed
This commit is contained in:
pyos
2021-09-07 11:42:02 +02:00
committed by Victor Petukhov
parent afa1d18cc2
commit 8f699248f1
12 changed files with 169 additions and 0 deletions
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -714,6 +714,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -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?
@@ -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?
@@ -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
}
@@ -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?
@@ -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
}
@@ -714,6 +714,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -714,6 +714,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -714,6 +714,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -796,6 +802,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
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
@TestMetadata("WildcardsWithDefault.kt")
public void testWildcardsWithDefault() throws Exception {
@@ -119,6 +119,16 @@ class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings
val enhanced = when {
!shouldEnhanceArguments -> Result(null, 0)
!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)
}
globalArgIndex += enhanced.subtreeSize