NI: Prefer nullable lower bound to flexible one when substitution of type variable is performed and remember flexibility of type parameters based on flexibility of its upper bounds
^KT-32435 Fixed
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: samConversionToGeneric.kt
|
||||
|
||||
fun test1() = J<String> { x -> x }
|
||||
|
||||
fun test2() = J { x: String -> x }
|
||||
|
||||
fun test3() = H.bar { x: String -> x }
|
||||
|
||||
fun test4(a: Any) {
|
||||
a as J<String>
|
||||
H.bar(a)
|
||||
}
|
||||
|
||||
fun test5(a: Any) {
|
||||
a as (String) -> String
|
||||
H.bar(a)
|
||||
}
|
||||
|
||||
fun <T> test6(a: (T) -> T) {
|
||||
H.bar(a)
|
||||
}
|
||||
|
||||
fun <T> test7(a: Any) {
|
||||
a as (T) -> T
|
||||
H.bar(a)
|
||||
}
|
||||
|
||||
fun test8(efn: String.() -> String) = J(efn)
|
||||
|
||||
fun test9(efn: String.() -> String) {
|
||||
H.bar(efn)
|
||||
}
|
||||
|
||||
fun test10(fn: (Int) -> String) {
|
||||
H.bar2x(fn)
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public interface J<T> {
|
||||
T foo(T x);
|
||||
}
|
||||
|
||||
// FILE: J2.java
|
||||
public interface J2<T1, T2> {
|
||||
T1 foo(T2 x);
|
||||
}
|
||||
|
||||
// FILE: J2X.java
|
||||
public interface J2X<T3> extends J2<String, T3> {
|
||||
}
|
||||
|
||||
// FILE: H.java
|
||||
public class H {
|
||||
public static <X> void bar(J<X> j) {}
|
||||
public static <Y> void bar2x(J2X<Y> j2x) {}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: samConversionToGeneric.kt
|
||||
|
||||
fun test1() = J<String> { x -> x }
|
||||
|
||||
fun test2() = J { x: String -> x }
|
||||
|
||||
fun test3() = H.bar { x: String -> x }
|
||||
|
||||
fun test4(a: Any) {
|
||||
a <!UNCHECKED_CAST!>as J<String><!>
|
||||
H.bar(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
|
||||
fun test5(a: Any) {
|
||||
a <!UNCHECKED_CAST!>as (String) -> String<!>
|
||||
H.bar(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
|
||||
fun <T> test6(a: (T) -> T) {
|
||||
H.bar(a)
|
||||
}
|
||||
|
||||
fun <T> test7(a: Any) {
|
||||
a <!UNCHECKED_CAST!>as (T) -> T<!>
|
||||
H.bar(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
|
||||
fun test8(efn: String.() -> String) = J(efn)
|
||||
|
||||
fun test9(efn: String.() -> String) {
|
||||
H.bar(efn)
|
||||
}
|
||||
|
||||
fun test10(fn: (Int) -> String) {
|
||||
H.bar2x(fn)
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public interface J<T> {
|
||||
T foo(T x);
|
||||
}
|
||||
|
||||
// FILE: J2.java
|
||||
public interface J2<T1, T2> {
|
||||
T1 foo(T2 x);
|
||||
}
|
||||
|
||||
// FILE: J2X.java
|
||||
public interface J2X<T3> extends J2<String, T3> {
|
||||
}
|
||||
|
||||
// FILE: H.java
|
||||
public class H {
|
||||
public static <X> void bar(J<X> j) {}
|
||||
public static <Y> void bar2x(J2X<Y> j2x) {}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package
|
||||
|
||||
public fun test1(): J<kotlin.String>
|
||||
public fun test10(/*0*/ fn: (kotlin.Int) -> kotlin.String): kotlin.Unit
|
||||
public fun test2(): J<kotlin.String!>
|
||||
public fun test3(): kotlin.Unit
|
||||
public fun test4(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun test5(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T> test6(/*0*/ a: (T) -> T): kotlin.Unit
|
||||
public fun </*0*/ T> test7(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun test8(/*0*/ efn: kotlin.String.() -> kotlin.String): J<kotlin.String!>
|
||||
public fun test9(/*0*/ efn: kotlin.String.() -> kotlin.String): kotlin.Unit
|
||||
|
||||
public open class H {
|
||||
public constructor H()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public open fun </*0*/ X : kotlin.Any!> bar(/*0*/ j: J<X!>!): kotlin.Unit
|
||||
public open fun </*0*/ Y : kotlin.Any!> bar2x(/*0*/ j2x: J2X<Y!>!): kotlin.Unit
|
||||
}
|
||||
|
||||
public interface J</*0*/ T : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ x: T!): T!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface J2</*0*/ T1 : kotlin.Any!, /*1*/ T2 : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ x: T2!): T1!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface J2X</*0*/ T3 : kotlin.Any!> : J2<kotlin.String!, T3!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ x: T3!): kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// NB new inference doesn't really work with old JVM back-end.
|
||||
|
||||
// WITH_JDK
|
||||
// FILE: samConversionsWithSmartCasts.kt
|
||||
|
||||
fun test1(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J.runStatic(a)
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run1(a)
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run2(a, a)
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(a: () -> Unit, b: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run2(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(a: Any) {
|
||||
if (a is Runnable) {
|
||||
J().run1(a)
|
||||
}
|
||||
}
|
||||
|
||||
fun test5x(a: Any) {
|
||||
if (a is Runnable) {
|
||||
a as () -> Unit
|
||||
J().run1(a)
|
||||
}
|
||||
}
|
||||
|
||||
fun test6(a: Any) {
|
||||
a as () -> Unit
|
||||
J().run1(a)
|
||||
}
|
||||
|
||||
fun test7(a: (Int) -> Int) {
|
||||
a as () -> Unit
|
||||
J().<!INAPPLICABLE_CANDIDATE!>run1<!>(a)
|
||||
}
|
||||
|
||||
fun test8(a: () -> Unit) {
|
||||
J().<!INAPPLICABLE_CANDIDATE!>run1<!>(J.id(a))
|
||||
}
|
||||
|
||||
fun test9() {
|
||||
J().run1(::test9)
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void runStatic(Runnable r) {}
|
||||
|
||||
public void run1(Runnable r) {}
|
||||
|
||||
public void run2(Runnable r1, Runnable r2) {}
|
||||
|
||||
public static <T> T id(T x) { return x; }
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// NB new inference doesn't really work with old JVM back-end.
|
||||
|
||||
// WITH_JDK
|
||||
// FILE: samConversionsWithSmartCasts.kt
|
||||
|
||||
fun test1(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J.runStatic(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run1(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(a: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run2(<!DEBUG_INFO_SMARTCAST!>a<!>, <!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(a: () -> Unit, b: () -> Unit) {
|
||||
if (a is Runnable) {
|
||||
J().run2(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(a: Any) {
|
||||
if (a is Runnable) {
|
||||
J().run1(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun test5x(a: Any) {
|
||||
if (a is Runnable) {
|
||||
a <!UNCHECKED_CAST!>as () -> Unit<!>
|
||||
J().run1(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun test6(a: Any) {
|
||||
a <!UNCHECKED_CAST!>as () -> Unit<!>
|
||||
J().run1(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
|
||||
fun test7(a: (Int) -> Int) {
|
||||
a <!UNCHECKED_CAST!>as () -> Unit<!>
|
||||
J().run1(<!DEBUG_INFO_SMARTCAST!>a<!>)
|
||||
}
|
||||
|
||||
fun test8(a: () -> Unit) {
|
||||
J().run1(J.id(a))
|
||||
}
|
||||
|
||||
fun test9() {
|
||||
J().run1(::test9)
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void runStatic(Runnable r) {}
|
||||
|
||||
public void run1(Runnable r) {}
|
||||
|
||||
public void run2(Runnable r1, Runnable r2) {}
|
||||
|
||||
public static <T> T id(T x) { return x; }
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public fun test1(/*0*/ a: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun test2(/*0*/ a: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun test3(/*0*/ a: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun test4(/*0*/ a: () -> kotlin.Unit, /*1*/ b: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun test5(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun test5x(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun test6(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun test7(/*0*/ a: (kotlin.Int) -> kotlin.Int): kotlin.Unit
|
||||
public fun test8(/*0*/ a: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun test9(): kotlin.Unit
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
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 fun run1(/*0*/ r: java.lang.Runnable!): kotlin.Unit
|
||||
public open fun run2(/*0*/ r1: java.lang.Runnable!, /*1*/ r2: java.lang.Runnable!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun </*0*/ T : kotlin.Any!> id(/*0*/ x: T!): T!
|
||||
public open fun runStatic(/*0*/ r: java.lang.Runnable!): kotlin.Unit
|
||||
}
|
||||
Reference in New Issue
Block a user