Reuse captured arguments for flexible type's bounds properly, by equality of type constructors modulo mutability and type argument

^KT-43630 Fixed
This commit is contained in:
Victor Petukhov
2020-12-01 17:24:50 +03:00
parent 9f58e4bcfe
commit d25ad269e0
8 changed files with 200 additions and 23 deletions
@@ -0,0 +1,23 @@
// FILE: Bar.java
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
public class Bar<K, N> { }
// FILE: Foo.java
public class Foo<P> extends Bar<Integer, Integer> {
public static final Bar bar = null;
}
// FILE: main.kt
fun <P> takeFoo(foo: Foo<P>) {}
fun main(x: Foo<*>?) {
val y = Foo.bar
if (y !is Foo<*>?) return
if (y == null) return
if (x != y) return
takeFoo(x) // Here we capture `{Bar<Any!, Any!> & Foo<*>}..Foo<*>?`
}
@@ -0,0 +1,23 @@
// FILE: Bar.java
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
public class Bar<K, N> { }
// FILE: Foo.java
public class Foo<P> extends Bar<Integer, Integer> {
public static final Bar bar = null;
}
// FILE: main.kt
fun <P> takeFoo(foo: Foo<P>) {}
fun main(x: Foo<*>?) {
val y = Foo.bar
if (y !is Foo<*>?) return
if (y == null) return
if (x != y) return
takeFoo(<!DEBUG_INFO_SMARTCAST!>x<!>) // Here we capture `{Bar<Any!, Any!> & Foo<*>}..Foo<*>?`
}
@@ -0,0 +1,29 @@
// FULL_JDK
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
// FILE: Bar.java
public class Bar<K, N> { }
// FILE: Foo.java
import java.util.List;
public class Foo<P> extends Bar<Integer, Integer> {
public static final List<?> bar = null;
}
// FILE: main.kt
fun <P> takeFoo(foo: Foo<P>) {}
fun main(x: Foo<*>?) {
val y = Foo.bar
if (y !is Foo<*>?) return
if (y == null) return
if (x != y) return
// Here we capture `({Foo<*> & MutableList<*>}..{Foo<*>? & List<*>?})`
// `*` inside `MutableList` and `List` have to become the same captured type
takeFoo(x)
}
@@ -0,0 +1,29 @@
// FULL_JDK
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
// FILE: Bar.java
public class Bar<K, N> { }
// FILE: Foo.java
import java.util.List;
public class Foo<P> extends Bar<Integer, Integer> {
public static final List<?> bar = null;
}
// FILE: main.kt
fun <P> takeFoo(foo: Foo<P>) {}
fun main(x: Foo<*>?) {
val y = Foo.bar
if (y !is Foo<*>?) return
if (y == null) return
if (x != y) return
// Here we capture `({Foo<*> & MutableList<*>}..{Foo<*>? & List<*>?})`
// `*` inside `MutableList` and `List` have to become the same captured type
takeFoo(<!DEBUG_INFO_SMARTCAST!>x<!>)
}