FIR: Refine inference constraints when type variable in flexible position
That issue might be fixed via changing TypeVariableMarker.shouldBeFlexible at ConeConstraintSystemUtilContext but this and some other tricks have been added because of incorrect handling of constraints where type variable has a flexible bound ^KT-51168 Fixed
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
// !LANGUAGE: +DefinitelyNonNullableTypes +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
|
||||
|
||||
// FILE: A.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public interface A<T> {
|
||||
public T foo(T x) { return x; }
|
||||
@NotNull
|
||||
public T bar(@NotNull T x) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface B<T1> : A<T1> {
|
||||
override fun foo(x: T1): T1
|
||||
override fun bar(x: T1 & Any): T1 & Any
|
||||
}
|
||||
|
||||
interface C<T2> : A<T2> {
|
||||
override fun foo(x: T2 & Any): T2 & Any
|
||||
<!NOTHING_TO_OVERRIDE!>override<!> fun bar(x: T2): T2
|
||||
}
|
||||
|
||||
interface D : A<String?> {
|
||||
override fun foo(x: String?): String?
|
||||
override fun bar(x: String): String
|
||||
}
|
||||
|
||||
interface E : A<String> {
|
||||
override fun foo(x: String): String
|
||||
override fun bar(x: String): String
|
||||
}
|
||||
|
||||
interface F : A<String?> {
|
||||
override fun foo(x: String): String
|
||||
<!NOTHING_TO_OVERRIDE!>override<!> fun bar(x: String?): String?
|
||||
}
|
||||
|
||||
interface G<T3 : Any> : A<T3> {
|
||||
override fun foo(x: T3): T3
|
||||
override fun bar(x: T3): T3
|
||||
}
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +DefinitelyNonNullableTypes +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -27,7 +27,7 @@ val xExplicit: X = Test().findViewById(0)
|
||||
val xCast = Test().findViewById(0) as X
|
||||
|
||||
val xCastExplicitType = Test().findViewById<X>(0) as X
|
||||
val xSafeCastExplicitType = Test().findViewById<X>(0) as? X
|
||||
val xSafeCastExplicitType = Test().findViewById<X>(0) <!USELESS_CAST!>as? X<!>
|
||||
|
||||
val yExplicit: Y<String> = Test().findViewById(0)
|
||||
val yCast = Test().findViewById(0) as Y<String>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// SKIP_TXT
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass {
|
||||
public static <K> K simpleId(K k) { // fun <K> simpleId(k: K & Any..K?): K & Any..K? =
|
||||
return k;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun takeN(n: Number?): Int = 1
|
||||
|
||||
fun bar(n: Number?) {
|
||||
fun takeN(n: Number): String = ""
|
||||
|
||||
// in K1, it was resolved to nullable takeN
|
||||
// in K2, it would be resolved to not-nullable and may fail with NPE
|
||||
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>div<!>(1)
|
||||
takeN(JavaClass.simpleId(n)).length
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// SKIP_TXT
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass {
|
||||
public static <K> K simpleId(K k) { // fun <K> simpleId(k: K & Any..K?): K & Any..K? =
|
||||
return k;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun takeN(n: Number?): Int = 1
|
||||
|
||||
fun bar(n: Number?) {
|
||||
fun takeN(n: Number): String = ""
|
||||
|
||||
// in K1, it was resolved to nullable takeN
|
||||
// in K2, it would be resolved to not-nullable and may fail with NPE
|
||||
takeN(JavaClass.simpleId(n)).div(1)
|
||||
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// FILE: XBreakpointProperties.java
|
||||
public abstract class XBreakpointProperties<T> {}
|
||||
// FILE: XBreakpoint.java
|
||||
public interface XBreakpoint<P extends XBreakpointProperties> {}
|
||||
// FILE: XBreakpointType.java
|
||||
public abstract class XBreakpointType<B extends XBreakpoint<P>, P extends XBreakpointProperties> {}
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: XBreakpointType<XBreakpoint<*>, *>) {}
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ public class A {
|
||||
fun test() {
|
||||
A.bar(null, "")
|
||||
|
||||
A.bar<String>(null, "")
|
||||
A.bar<String>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
A.bar<String?>(null, "")
|
||||
A.bar(null, A.platformString())
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo() {
|
||||
val list = ArrayList<String?>()
|
||||
|
||||
for (s in list) {
|
||||
s.length
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo() {
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// FILE: ExtensionPointName.java
|
||||
public final class ExtensionPointName<T> {}
|
||||
// FILE: ExtensionPoint.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ExtensionPoint<@NotNull T> {
|
||||
T foo();
|
||||
}
|
||||
// FILE: Area.java
|
||||
public class Area {
|
||||
@NotNull
|
||||
public static <T> ExtensionPoint<T> getExtensionPoint(@NotNull ExtensionPointName<T> extensionPointName) { return null; }
|
||||
}
|
||||
// FILE: main.kt
|
||||
|
||||
private fun unregisterEverything(extensionPoint: ExtensionPointName<*>) {
|
||||
Area.getExtensionPoint(extensionPoint).foo().hashCode()
|
||||
}
|
||||
Reference in New Issue
Block a user