Allow bare types on the right-hand side of as/as?/is/!is
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
trait Tr
|
||||
trait G<T>
|
||||
|
||||
fun test(tr: Tr): Any {
|
||||
return tr as G<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>>
|
||||
}
|
||||
|
||||
fun test1(tr: Tr): Any {
|
||||
return tr as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>.(<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>) -> <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
trait Tr<T>
|
||||
trait 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:
|
||||
v!!: G<String>
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
trait Either<out A, out B>
|
||||
trait Left<out A>: Either<A, Nothing>
|
||||
trait 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 v: Left<C1>
|
||||
}
|
||||
|
||||
fun _as_right(e: Either<C1, C2>): Any {
|
||||
val v = e as Right
|
||||
return v: Right<C2>
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
trait Either<out A, out B>
|
||||
trait Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
trait 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.v1
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
fun _is_r(e: Either<C1, C2>): Any {
|
||||
if (e is Right) {
|
||||
return e.value.v2
|
||||
}
|
||||
return e
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
trait Either<out A, out B>
|
||||
trait Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
trait 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.v1
|
||||
}
|
||||
|
||||
fun _is_r(e: Either<C1, C2>): Any {
|
||||
if (e !is Right) {
|
||||
return e
|
||||
}
|
||||
return e.value.v2
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
trait Either<out A, out B>
|
||||
trait Left<out A>: Either<A, Nothing>
|
||||
trait 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 v: Left<C1>?
|
||||
}
|
||||
|
||||
fun _as_right(e: Either<C1, C2>): Any? {
|
||||
val v = e as? Right
|
||||
return v: Right<C2>?
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
trait Either<out A, out B>
|
||||
trait Left<out A>: Either<A, Nothing> {
|
||||
val value: A
|
||||
}
|
||||
trait 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.v1
|
||||
is Right -> e.value.v2
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
trait B<T>
|
||||
trait G<T>: B<T>
|
||||
|
||||
fun f(p: B<<!UNRESOLVED_REFERENCE!>Foo<!>>): Any {
|
||||
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> as G
|
||||
return <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>v<!>: G<*>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
trait Tr<T>
|
||||
trait G<T> : Tr<T>
|
||||
|
||||
fun test(tr: Tr<String>?) {
|
||||
val v = tr as G
|
||||
v: G<String>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
trait B<T>
|
||||
class G<T>: B<T>
|
||||
|
||||
fun f(b: B<String>?) = b is G?<!REDUNDANT_NULLABLE!>?<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
class P
|
||||
|
||||
fun foo(p: P): Any {
|
||||
val v = p <!USELESS_CAST!>as<!> <!UNRESOLVED_REFERENCE!>G<!>
|
||||
return <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>v<!>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
trait Tr
|
||||
trait G<T>
|
||||
|
||||
fun test(tr: Tr) {
|
||||
val v = tr as G
|
||||
v: G<*>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
trait Tr
|
||||
trait G<T>
|
||||
|
||||
fun test(tr: Tr) = tr: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
|
||||
@@ -0,0 +1,4 @@
|
||||
trait Tr
|
||||
trait G<T>
|
||||
|
||||
fun test(tr: Tr) = tr is G
|
||||
Reference in New Issue
Block a user