[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
fun f(x: Any) = x as Array<String>
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun ff(c: MutableCollection<String>) = c as MutableList<Int>
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun ff(c: MutableCollection<String>) = c as MutableList<String>
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
fun ff(l: Any) = l as MutableList<*>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun ff(a: Any) = a as MutableList<String>
|
||||
@@ -0,0 +1,31 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Base
|
||||
|
||||
class Impl1 : Base
|
||||
|
||||
class Impl2 : Base
|
||||
|
||||
operator fun Base.plus(arg: Base) = Impl1()
|
||||
|
||||
operator fun Impl2.plus(arg: Base) = Impl2()
|
||||
|
||||
operator fun Base.plus(arg: Impl2) = Impl2()
|
||||
|
||||
operator fun Base.unaryMinus() = Impl1()
|
||||
|
||||
operator fun Impl2.unaryMinus() = Impl2()
|
||||
|
||||
// See also KT-10384: in non-error functions, as is necessary!
|
||||
fun add1(x: Impl2, y: Base): Impl1 = x as Base + y
|
||||
|
||||
fun error1(x: Impl2, y: Base): Impl1 = x + y
|
||||
|
||||
fun add2(x: Base, y: Impl2): Impl1 = x + y as Base
|
||||
|
||||
fun error2(x: Base, y: Impl2): Impl1 = x + y
|
||||
|
||||
fun minus3(x: Impl2): Impl1 = -(x as Base)
|
||||
|
||||
fun error3(x: Impl2): Impl1 = -x
|
||||
@@ -0,0 +1,53 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun runWithoutReturn(r: () -> Unit) = r()
|
||||
|
||||
fun testRun() {
|
||||
run {
|
||||
1 as Any
|
||||
1 as Any
|
||||
}
|
||||
|
||||
run<Any> {
|
||||
1 as Any
|
||||
1 as Any
|
||||
}
|
||||
|
||||
fun foo(): Int = 1
|
||||
|
||||
run {
|
||||
foo() as Any
|
||||
}
|
||||
|
||||
run {
|
||||
(if (true) 1 else 2) as Any
|
||||
}
|
||||
|
||||
run<Int?> {
|
||||
1 as Int
|
||||
1 as Int
|
||||
}
|
||||
|
||||
runWithoutReturn {
|
||||
1 as Any
|
||||
1 as Any
|
||||
}
|
||||
}
|
||||
|
||||
fun testReturn(): Number {
|
||||
run { 1 as Number }
|
||||
return run { 1 as Number }
|
||||
}
|
||||
|
||||
fun <T> testDependent() {
|
||||
listOf(1).map {
|
||||
it as Any
|
||||
it as Any
|
||||
}
|
||||
|
||||
listOf<T>().map { it as Any? }
|
||||
}
|
||||
|
||||
fun <T> listOf(vararg elements: T): List<T> = TODO()
|
||||
fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> = TODO()
|
||||
@@ -0,0 +1,12 @@
|
||||
fun <T> id(x: T): T = x
|
||||
|
||||
fun foo() = 1 as Any
|
||||
fun bar() = id(1) as Any
|
||||
fun baz() = (1 + 1) as Any
|
||||
|
||||
val functionLiteral1 = fun() = 1 as Any
|
||||
val functionLiteral2 = fun() = id(1) as Any
|
||||
val functionLiteral3 = fun() = (1 + 1) as Any
|
||||
|
||||
// TODO: this and more complex cases are not supported yet
|
||||
fun baz(b: Boolean) = if (b) 1 as Any else 42 as Any?
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun test() {
|
||||
val a = 1 as Any?
|
||||
val b: Number = 1 as Number
|
||||
val c = null as String?
|
||||
val d: Number = 1 as Int
|
||||
}
|
||||
|
||||
val c1 get() = 1 as Number
|
||||
val c2: Number get() = 1 as Number
|
||||
|
||||
val d: Number
|
||||
get() {
|
||||
1 as Number
|
||||
return 1 as Number
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Nothing can be cast to Nothing
|
||||
fun foo(x: String) {
|
||||
x as Nothing
|
||||
}
|
||||
|
||||
fun gav(y: String?) {
|
||||
y as Nothing
|
||||
}
|
||||
|
||||
// Only nullable can be cast to Nothing?
|
||||
fun bar(x: String, y: String?) {
|
||||
x as Nothing?
|
||||
y as Nothing?
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
typealias MyString = String
|
||||
|
||||
val x: MyString = ""
|
||||
val y = x as Any
|
||||
|
||||
interface Base
|
||||
class Derived : Base
|
||||
interface Other : Base
|
||||
typealias IBase = Base
|
||||
typealias IOther = Other
|
||||
|
||||
val ib: IBase = Derived()
|
||||
val d = ib as Derived
|
||||
val o = ib as Other
|
||||
val io = ib as IOther
|
||||
val s = d as String
|
||||
val ms = d as MyString
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// See also: KT-6611 (cast can never succeed: Class<T> -> Class<Any>)
|
||||
|
||||
class Class<T>(val name: String, val instance: T)
|
||||
|
||||
fun <T> test(clazz: Class<T>) {
|
||||
println((clazz as Class<Any>).name)
|
||||
}
|
||||
|
||||
fun use() {
|
||||
test(Class("String", ""))
|
||||
}
|
||||
|
||||
fun checkArrays(): Array<Any> {
|
||||
val someArray = arrayOfNulls<Any>(5)
|
||||
someArray as Array<Int>
|
||||
return someArray as Array<Any>
|
||||
}
|
||||
|
||||
class Wrapper<T>(val x: T)
|
||||
|
||||
fun checkArrays2(): Array<Wrapper<String>> {
|
||||
val someArray = arrayOf(Wrapper(1), Wrapper(2))
|
||||
return someArray as Array<Wrapper<String>>
|
||||
}
|
||||
|
||||
fun checkArrays3() {
|
||||
val someArray = arrayOfNulls<String>(1)
|
||||
someArray as Array<Any>
|
||||
val intArray = arrayOfNulls<Int>(1)
|
||||
intArray as Array<Any>
|
||||
}
|
||||
|
||||
fun println(s: String) = s
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
interface Map<K, out V>
|
||||
interface MutableMap<K, V>: Map<K, V> {
|
||||
operator fun set(k: K, v: V)
|
||||
}
|
||||
|
||||
fun p(p: Map<String, Int>) {
|
||||
if (p is MutableMap<String, Int>) {
|
||||
p[""] = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun f(a: (Int) -> Unit) {
|
||||
a as Int.() -> Unit
|
||||
|
||||
f1(a as Int.() -> Unit)
|
||||
}
|
||||
|
||||
fun f1(a: Int.() -> Unit) {
|
||||
a as (Int) -> Unit
|
||||
f(a as (Int) -> Unit)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// FILE: Foo.java
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Foo {
|
||||
static Foo create() { return null; }
|
||||
|
||||
@Nullable
|
||||
static Foo createN() { return null; }
|
||||
|
||||
@NotNull
|
||||
static Foo createNN() { return null; }
|
||||
}
|
||||
|
||||
// FILE: sample.kt
|
||||
|
||||
fun test() {
|
||||
Foo.create() as Foo
|
||||
Foo.createN() as Foo
|
||||
Foo.createNN() as Foo
|
||||
|
||||
Foo.create() as Foo?
|
||||
Foo.createN() as Foo?
|
||||
Foo.createNN() as Foo?
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class BaseTwo<A, B>
|
||||
open class DerivedWithOne<D>: BaseTwo<D, String>()
|
||||
|
||||
// a is BaseTwo<T, U> => if (a is DerivedWithOne<?>) a is DerivedWithOne<T>
|
||||
fun <T, U> testing(a: BaseTwo<T, U>) = a is DerivedWithOne<T>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class Base<A>
|
||||
class Some: Base<Int>()
|
||||
|
||||
// a is Some => a is Base<Int>
|
||||
fun f(a: Some) = a is Base<Int>
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
|
||||
open class Base<out T>
|
||||
open class SubBase<T> : Base<T>()
|
||||
|
||||
// l is Base<+B> => if (l is SubBase<?>) l is SubBase<+B> => l is SubBase<+A>
|
||||
fun ff(l: Base<B>) = l is SubBase<out A>
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
|
||||
open class Base<in T>
|
||||
class SubBase: Base<A>()
|
||||
|
||||
// f is SubBase => f is Base<A> => (Base<Contravariant T>, B <: A) f is Base<B>
|
||||
fun test(f: SubBase) = f is Base<B>
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
|
||||
open class Base<out T>
|
||||
class SubBase: Base<B>()
|
||||
|
||||
// f is SubBase => (SubBase <: Base<B>) f is Base<B> => (B <: A, Base<Covariant T> => SubBase <: Base<A>) f is Base<A>
|
||||
fun test(f: SubBase) = f is Base<A>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface A
|
||||
interface B: A
|
||||
interface D
|
||||
|
||||
interface BaseSuper<out T>
|
||||
interface BaseImpl: BaseSuper<D>
|
||||
interface DerivedSuper<out S>: BaseSuper<S>, BaseImpl
|
||||
|
||||
fun test(t: BaseSuper<B>) = t is DerivedSuper<A>
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
open class BaseMulti<out A, B>
|
||||
class SomeMultiDerived<out D>: BaseMulti<D, Any>()
|
||||
|
||||
// t is BaseMulti<+String, String> => if (t is SomeMultiDerived<?>) => t is SomeMultiDerived<+String> =>
|
||||
// => (String <: Any, SomeMultiDerived<Covariant D>) t is SomeMultiDerived<+Any>
|
||||
fun someDerived(t: BaseMulti<String, String>) = t is SomeMultiDerived<Any>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class Base<A>
|
||||
class Some: Base<Int>()
|
||||
|
||||
// No erased types in check
|
||||
fun <A> f(a: Base<A>) = a is Some
|
||||
@@ -0,0 +1 @@
|
||||
fun f(a: MutableList<out Number>) = a is MutableList<out Any>
|
||||
@@ -0,0 +1 @@
|
||||
fun f(a: MutableList<String>) = a is MutableList<out CharSequence>
|
||||
@@ -0,0 +1 @@
|
||||
fun f(a: List<Number>) = a is List<Any>
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
open class A
|
||||
|
||||
class B : A()
|
||||
|
||||
fun ff(l: MutableCollection<B>) = l is MutableList<out A>
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
fun ff(l: MutableCollection<String>) = l is MutableList<String>
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
fun <T> ff(l: MutableCollection<T>) = l is MutableList<T>
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun f(a: MutableList<String>) = a is MutableList<CharSequence>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
|
||||
open class Base<out T>
|
||||
open class SubBase<T> : Base<T>()
|
||||
|
||||
|
||||
fun ff(l: Base<B>) = l is SubBase<A>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
interface A
|
||||
interface B: A
|
||||
|
||||
interface Base<T>
|
||||
|
||||
fun <T> test(a: Base<B>) where T: Base<A> = a is T
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun ff(l: Any) = l is MutableList<String>
|
||||
@@ -0,0 +1 @@
|
||||
fun f(a: MutableList<in String>) = a is MutableList<CharSequence>
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun f(a : MutableList<out Any>) = a is MutableList<out Int>
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun f(a: List<Any>) = a is List<Number>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
open class D
|
||||
|
||||
open class Base<out T, out U>
|
||||
open class Derived<out S>: Base<S, S>()
|
||||
|
||||
fun test(a: Base<D, B>) = a is Derived<A>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class A
|
||||
open class B: A()
|
||||
open class D
|
||||
|
||||
open class Base<out T, out U>
|
||||
open class Derived<out S>: Base<S, S>()
|
||||
|
||||
fun test(a: Base<B, D>) = a is Derived<A>
|
||||
@@ -0,0 +1,3 @@
|
||||
interface A
|
||||
interface B
|
||||
fun testing(a: A) = a as B
|
||||
@@ -0,0 +1 @@
|
||||
fun <T: Any> testing(a: T?) = a is T
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
fun ff(l: Any) = l is MutableList<*>
|
||||
@@ -0,0 +1 @@
|
||||
fun <T> testing(a: T) = a is T
|
||||
@@ -0,0 +1 @@
|
||||
fun testing(a: Any) = a is UnresolvedType<Int>
|
||||
@@ -0,0 +1,27 @@
|
||||
fun <T, S : T> test(x: T?, y: S, z: T) {
|
||||
x is T
|
||||
x is T?
|
||||
|
||||
y is T
|
||||
y is S
|
||||
y is T?
|
||||
y is S?
|
||||
|
||||
z is T
|
||||
z is T?
|
||||
|
||||
null as T
|
||||
null as T?
|
||||
null as S
|
||||
}
|
||||
|
||||
inline fun <reified T> test(x: T?) {
|
||||
x is T
|
||||
null as T
|
||||
null as T?
|
||||
}
|
||||
|
||||
fun <T> foo(x: List<T>, y: List<T>?) {
|
||||
x is List<T>
|
||||
y is List<T>
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
interface A<T>
|
||||
class B : A<String> {}
|
||||
|
||||
fun <T, U : A<T>> test1(a: U) {
|
||||
a is B
|
||||
}
|
||||
|
||||
fun <T, S : A<T>, U : S> test2(a: U) {
|
||||
a is B
|
||||
}
|
||||
|
||||
fun <T : A<String>, V : A<Int>> test3(a: T, b: V) {
|
||||
a is B
|
||||
b is B
|
||||
}
|
||||
|
||||
fun <T, V : A<out T>> test4(a: T, b: V) {
|
||||
a is B
|
||||
b is B
|
||||
}
|
||||
|
||||
interface Out<out T>
|
||||
class OutNothing : Out<Nothing>
|
||||
|
||||
fun <T, S : Out<T>> test5(a: S) {
|
||||
a is OutNothing
|
||||
}
|
||||
|
||||
interface In<in T>
|
||||
class InNothing : In<Nothing>
|
||||
|
||||
fun <T, S : In<T>> test6(a: S) {
|
||||
a is InNothing
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
open class RecA<T>: RecB<T>()
|
||||
open class RecB<T>: <!OTHER_ERROR!>RecA<T><!>()
|
||||
open class SelfR<T>: <!OTHER_ERROR!>SelfR<T><!>()
|
||||
|
||||
fun test(f: SelfR<String>) = f is RecA<String>
|
||||
fun test(f: RecB<String>) = f is RecA<String>
|
||||
@@ -0,0 +1,4 @@
|
||||
interface Aaa
|
||||
interface Bbb
|
||||
|
||||
fun f(a: Aaa) = a is Bbb
|
||||
@@ -0,0 +1,14 @@
|
||||
// check that there is no SOE on checking for instance
|
||||
interface Visitor<T>
|
||||
interface Acceptor<T>
|
||||
|
||||
class Word : Acceptor<Visitor<Word>>
|
||||
|
||||
class V : Visitor<Word>
|
||||
|
||||
class S<T : Acceptor<U>, U : Visitor<T>>(val visitor: U, val acceptor: T) {
|
||||
fun test() {
|
||||
visitor is V
|
||||
acceptor is Word
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// From KT-13324: always succeeds
|
||||
val x = null as String?
|
||||
// From KT-260: sometimes succeeds
|
||||
fun foo(a: String?): Int? {
|
||||
val c = a as? Int?
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface I1
|
||||
interface I2
|
||||
|
||||
fun foo(i: I1) {}
|
||||
fun foo(i: I2) {}
|
||||
|
||||
fun bar(i: I1) {
|
||||
if (i is I2) {
|
||||
foo(i as I1)
|
||||
foo(i as I2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
|
||||
|
||||
fun test(x: Int?) {
|
||||
val a1 = x as? Int
|
||||
val a2 = x as? Int?
|
||||
val a3 = x as? Number
|
||||
val a4 = x as? Number?
|
||||
val a5: Int? = x as? Int
|
||||
val a6: Number? = x as? Int
|
||||
val a7: Number? = 1 as? Number
|
||||
|
||||
run { x as? Int }
|
||||
run { x as? Number }
|
||||
|
||||
foo(x as? Number)
|
||||
|
||||
if (x is Int) {
|
||||
val b = x as? Int
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(x: Number?) {}
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
fun ff(l: Any) = when(l) {
|
||||
is MutableList<String> -> 1
|
||||
else <!SYNTAX!>2<!>
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class List<out T>(val size : Int) {
|
||||
companion object {
|
||||
val Nil = List<Nothing>(0)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<String>.join() =
|
||||
when (this) {
|
||||
List.Nil -> "[]" // CANNOT_CHECK_FOR_ERASED was reported
|
||||
else -> ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr): Any {
|
||||
return tr as G<G>
|
||||
}
|
||||
|
||||
fun test1(tr: Tr): Any {
|
||||
return tr as G.(G) -> G
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr<T>
|
||||
interface G<T> : Tr<T>
|
||||
|
||||
fun test(tr: Tr<String>) {
|
||||
val v = tr as G?
|
||||
// If v is not nullable, there will be a warning on this line:
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<String>>(v!!)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) {
|
||||
val v = tr as G?
|
||||
// If v is not nullable, there will be a warning on this line:
|
||||
checkSubtype<G<*>>(v!!)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Either<out A, out B>
|
||||
interface Left<out A>: Either<A, Nothing>
|
||||
interface Right<out B>: Either<Nothing, B>
|
||||
|
||||
class C1(val v1: Int)
|
||||
class C2(val v2: Int)
|
||||
|
||||
fun _as_left(e: Either<C1, C2>): Any {
|
||||
val v = e as Left
|
||||
return <!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Left<C1>>(v)
|
||||
}
|
||||
|
||||
fun _as_right(e: Either<C1, C2>): Any {
|
||||
val v = e as Right
|
||||
return <!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Right<C2>>(v)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
interface Either<out A, out B>
|
||||
interface Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
interface Right<out B>: Either<Nothing, B> {
|
||||
val value: B
|
||||
}
|
||||
|
||||
class C1(val v1: Int)
|
||||
class C2(val v2: Int)
|
||||
|
||||
fun _is_l(e: Either<C1, C2>): Any {
|
||||
if (e is Left) {
|
||||
return e.value.<!UNRESOLVED_REFERENCE!>v1<!>
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
fun _is_r(e: Either<C1, C2>): Any {
|
||||
if (e is Right) {
|
||||
return e.value.<!UNRESOLVED_REFERENCE!>v2<!>
|
||||
}
|
||||
return e
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
interface Either<out A, out B>
|
||||
interface Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
interface Right<out B>: Either<Nothing, B> {
|
||||
val value: B
|
||||
}
|
||||
|
||||
class C1(val v1: Int)
|
||||
class C2(val v2: Int)
|
||||
|
||||
fun _is_l(e: Either<C1, C2>): Any {
|
||||
if (e !is Left) {
|
||||
return e
|
||||
}
|
||||
return e.value.<!UNRESOLVED_REFERENCE!>v1<!>
|
||||
}
|
||||
|
||||
fun _is_r(e: Either<C1, C2>): Any {
|
||||
if (e !is Right) {
|
||||
return e
|
||||
}
|
||||
return e.value.<!UNRESOLVED_REFERENCE!>v2<!>
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Either<out A, out B>
|
||||
interface Left<out A>: Either<A, Nothing>
|
||||
interface Right<out B>: Either<Nothing, B>
|
||||
|
||||
class C1(val v1: Int)
|
||||
class C2(val v2: Int)
|
||||
|
||||
fun _as_left(e: Either<C1, C2>): Any? {
|
||||
val v = e as? Left
|
||||
return <!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Left<C1>?>(v)
|
||||
}
|
||||
|
||||
fun _as_right(e: Either<C1, C2>): Any? {
|
||||
val v = e as? Right
|
||||
return <!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Right<C2>?>(v)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
|
||||
interface Either<out A, out B>
|
||||
interface Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
interface Right<out B>: Either<Nothing, B> {
|
||||
val value: B
|
||||
}
|
||||
|
||||
class C1(val v1: Int)
|
||||
class C2(val v2: Int)
|
||||
|
||||
fun _when(e: Either<C1, C2>): Any {
|
||||
return when (e) {
|
||||
is Left -> e.value.<!UNRESOLVED_REFERENCE!>v1<!>
|
||||
is Right -> e.value.<!UNRESOLVED_REFERENCE!>v2<!>
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface B<T>
|
||||
interface G<T>: B<T>
|
||||
|
||||
fun f(p: B<Foo>): Any {
|
||||
val v = p as G
|
||||
return checkSubtype<G<*>>(v)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
class G<T>
|
||||
|
||||
fun foo(p: P) {
|
||||
val v = p as G?
|
||||
checkSubtype<G<*>>(v!!)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr<T>
|
||||
interface G<T> : Tr<T>
|
||||
|
||||
fun test(tr: Tr<String>?) {
|
||||
val v = tr as G
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<String>>(v)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr?) {
|
||||
val v = tr as G
|
||||
checkSubtype<G<*>>(v)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr<T>
|
||||
interface G<T> : Tr<T>
|
||||
|
||||
fun test(tr: Tr<String>?) {
|
||||
val v = tr as G?
|
||||
// If v is not nullable, there will be a warning on this line:
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<String>>(v!!)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr?) {
|
||||
val v = tr as G?
|
||||
checkSubtype<G<*>>(v!!)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
interface B<T>
|
||||
class G<T>: B<T>
|
||||
|
||||
fun f(b: B<String>?) = b is G??
|
||||
@@ -0,0 +1,6 @@
|
||||
class P
|
||||
|
||||
fun foo(p: P): Any {
|
||||
val v = p as G
|
||||
return v
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) {
|
||||
val v = tr as G
|
||||
checkSubtype<G<*>>(v)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// !CHECK_TYPE
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) = <!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G>(tr)
|
||||
@@ -0,0 +1,4 @@
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) = tr is G
|
||||
@@ -0,0 +1,38 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaClass {
|
||||
static Integer foo() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Integer fooN() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static Integer fooNN() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun <T, S: Any> test(x1: T, x2: T?, y1: S, y2: S?) {
|
||||
x1 is T?
|
||||
x2 is T?
|
||||
y1 is S?
|
||||
y2 is S?
|
||||
|
||||
val f1 = JavaClass.foo()
|
||||
f1 is Int?
|
||||
|
||||
val f2 = JavaClass.fooN()
|
||||
f2 is Int?
|
||||
|
||||
val f3 = JavaClass.fooNN()
|
||||
f3 is Int?
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
fun asCall() {
|
||||
1 as Int
|
||||
1 as Byte
|
||||
1 as Short
|
||||
1 as Long
|
||||
1 as Char
|
||||
1 as Double
|
||||
1 as Float
|
||||
|
||||
1.0 as Int
|
||||
1.0 as Byte
|
||||
1.0 as Short
|
||||
1.0 as Long
|
||||
1.0 as Char
|
||||
1.0 as Double
|
||||
1.0 as Float
|
||||
|
||||
1f as Int
|
||||
1f as Byte
|
||||
1f as Short
|
||||
1f as Long
|
||||
1f as Char
|
||||
1f as Double
|
||||
1f as Float
|
||||
}
|
||||
|
||||
fun asSafe() {
|
||||
1 as? Int
|
||||
1 as? Byte
|
||||
1 as? Short
|
||||
1 as? Long
|
||||
1 as? Char
|
||||
1 as? Double
|
||||
1 as? Float
|
||||
|
||||
1.0 as? Int
|
||||
1.0 as? Byte
|
||||
1.0 as? Short
|
||||
1.0 as? Long
|
||||
1.0 as? Char
|
||||
1.0 as? Double
|
||||
1.0 as? Float
|
||||
|
||||
1f as? Int
|
||||
1f as? Byte
|
||||
1f as? Short
|
||||
1f as? Long
|
||||
1f as? Char
|
||||
1f as? Double
|
||||
1f as? Float
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class G<T>
|
||||
|
||||
fun f(q: Any) = q is G<*>
|
||||
@@ -0,0 +1,3 @@
|
||||
class G<T>
|
||||
|
||||
fun <Q> f(q: Q) = q is G<*>
|
||||
@@ -0,0 +1,4 @@
|
||||
class G<T>
|
||||
interface Tr
|
||||
|
||||
fun f(q: Tr) = q is G<*>
|
||||
@@ -0,0 +1,7 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class Array<E>(e: E) {
|
||||
val k = Array(1) {
|
||||
1 as Any
|
||||
e as Any?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun f(a: Collection<*>) = a is List<*>?
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class A {
|
||||
fun foo() {}
|
||||
}
|
||||
class B : A()
|
||||
|
||||
fun test(b: B?) {
|
||||
(b as A).foo()
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS
|
||||
import java.lang.String as JString
|
||||
import java.lang.CharSequence as JCS
|
||||
|
||||
fun test(
|
||||
s: String,
|
||||
js: JString,
|
||||
cs: CharSequence,
|
||||
jcs: JCS
|
||||
) {
|
||||
s as JString
|
||||
s as JCS
|
||||
s as CharSequence
|
||||
s as String
|
||||
|
||||
js as JString
|
||||
js as JCS
|
||||
js as CharSequence
|
||||
js as String
|
||||
|
||||
cs as JString
|
||||
cs as JCS
|
||||
cs as CharSequence
|
||||
cs as String
|
||||
|
||||
jcs as JString
|
||||
jcs as JCS
|
||||
jcs as CharSequence
|
||||
jcs as String
|
||||
|
||||
jcs as Int
|
||||
s as java.lang.Integer
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS -ABSTRACT_MEMBER_NOT_IMPLEMENTED
|
||||
import java.lang.CharSequence as JCS
|
||||
|
||||
class JSub: JCS
|
||||
class Sub: CharSequence
|
||||
|
||||
fun test(
|
||||
s: Sub,
|
||||
js: JSub,
|
||||
cs: CharSequence,
|
||||
jcs: JCS
|
||||
) {
|
||||
// js as CharSequence // - this case is not supported due to limitation in PlatformToKotlinClassMap
|
||||
js as JCS
|
||||
|
||||
s as CharSequence
|
||||
s as JCS
|
||||
|
||||
js as Sub
|
||||
s as JSub
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS
|
||||
interface T1
|
||||
interface T2
|
||||
interface T3
|
||||
open class OC1: T1
|
||||
open class OC2: OC1(), T2
|
||||
class FC1: OC2(), T3
|
||||
interface T4: OC1
|
||||
interface T5: T2
|
||||
|
||||
fun <TP1: OC1, TP2: T2, TP3: OC2> test(
|
||||
t2: T2,
|
||||
t4: T4,
|
||||
fc1: FC1,
|
||||
oc1: OC1,
|
||||
oc2: OC2,
|
||||
tp1: TP1,
|
||||
tp2: TP2
|
||||
) {
|
||||
fc1 as FC1
|
||||
fc1 as OC1
|
||||
fc1 as T1
|
||||
fc1 as TP1
|
||||
|
||||
oc1 as FC1
|
||||
oc1 as OC2
|
||||
oc2 as OC1
|
||||
oc1 as T2
|
||||
oc1 as T1
|
||||
oc1 as TP1
|
||||
oc1 as TP2
|
||||
|
||||
t2 as FC1
|
||||
t2 as OC2
|
||||
t4 as OC1
|
||||
t2 as T2
|
||||
t2 as T5
|
||||
t2 as TP2
|
||||
|
||||
tp1 as FC1
|
||||
tp1 as OC1
|
||||
tp1 as OC2
|
||||
tp2 as T2
|
||||
tp2 as T5
|
||||
tp1 as TP3
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS
|
||||
interface Trait1
|
||||
interface Trait2
|
||||
open class OClass1
|
||||
open class OClass2
|
||||
class FClass1
|
||||
class FClass2
|
||||
|
||||
fun <TP1: OClass1, TP2: OClass2> test(
|
||||
t1: Trait1,
|
||||
oc1: OClass1,
|
||||
fc1: FClass1,
|
||||
tp1: TP1
|
||||
) {
|
||||
t1 as Trait2
|
||||
t1 as OClass2
|
||||
t1 as FClass2
|
||||
t1 as TP2
|
||||
|
||||
oc1 as Trait2
|
||||
oc1 as OClass2
|
||||
oc1 as FClass2
|
||||
oc1 as TP2
|
||||
|
||||
fc1 as Trait2
|
||||
fc1 as OClass2
|
||||
fc1 as FClass2
|
||||
fc1 as TP2
|
||||
|
||||
tp1 as Trait2
|
||||
tp1 as OClass2
|
||||
tp1 as FClass2
|
||||
tp1 as TP2
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// !DIAGNOSTICS: -UNREACHABLE_CODE
|
||||
|
||||
fun TODO(): Nothing = throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalStateException<!>()
|
||||
|
||||
open class OpenClass
|
||||
class FinalClass : OpenClass()
|
||||
abstract class AbstractClass
|
||||
interface Interface
|
||||
|
||||
fun test() {
|
||||
TODO() as Any
|
||||
TODO() as Any?
|
||||
TODO() as OpenClass
|
||||
TODO() as FinalClass
|
||||
TODO() as AbstractClass
|
||||
TODO() as Interface
|
||||
|
||||
val a = TODO() as Any
|
||||
val b = TODO() as Any?
|
||||
val c = TODO() as OpenClass
|
||||
val d = TODO() as FinalClass
|
||||
val e = TODO() as AbstractClass
|
||||
val f = TODO() as Interface
|
||||
}
|
||||
|
||||
fun a() = TODO() as Any
|
||||
fun b() = TODO() as Any?
|
||||
fun c() = TODO() as OpenClass
|
||||
fun d() = TODO() as FinalClass
|
||||
fun e() = TODO() as AbstractClass
|
||||
fun f() = TODO() as Interface
|
||||
Reference in New Issue
Block a user