CastExpressionFix

This commit is contained in:
Wojciech Lopata
2013-04-14 15:34:58 +02:00
committed by Evgeny Gerashchenko
parent 59716fec9c
commit b3a87d943a
19 changed files with 320 additions and 3 deletions
@@ -0,0 +1,12 @@
// "Cast expression 'a' to 'Foo'" "true"
trait Foo {
fun plus(x: Any) : Foo
}
fun foo(_a: Any): Any {
var a = _a
if (a is Foo) {
return a as Foo + a
}
return 42
}
@@ -0,0 +1,12 @@
// "Cast expression 'a' to 'Foo'" "true"
trait Foo {
fun not() : Foo
}
fun foo(_a: Any): Any {
var a = _a
if (a is Foo) {
return !(a as Foo)
}
return 42
}
@@ -0,0 +1,11 @@
// "Cast expression 'x' to 'Foo<Number>'" "true"
trait Foo<out T: Number> {
fun foo(x: T)
}
fun bar(_x: Any) {
var x = _x
if (x is Foo<*>) {
(x as Foo<Number>)<caret>.foo(42)
}
}
@@ -0,0 +1,6 @@
// "Cast expression 'Foo<Number>()' to 'Foo<Int>'" "true"
class Foo<out T>
fun foo(): Foo<Int> {
return Foo<Number>() as Foo<Int><caret>
}
@@ -0,0 +1,9 @@
// "Cast expression 'a + a' to 'B'" "true"
trait A {
fun plus(x: Any): A
}
trait B : A
fun foo(a: A): B {
return (a + a) as B<caret>
}
@@ -0,0 +1,12 @@
// "Cast expression 'a' to 'Foo'" "true"
trait Foo {
fun plus(x: Any) : Foo
}
fun foo(_a: Any): Any {
var a = _a
if (a is Foo) {
return a<caret> + a
}
return 42
}
@@ -0,0 +1,12 @@
// "Cast expression 'a' to 'Foo'" "true"
trait Foo {
fun not() : Foo
}
fun foo(_a: Any): Any {
var a = _a
if (a is Foo) {
return !a<caret>
}
return 42
}
@@ -0,0 +1,11 @@
// "Cast expression 'x' to 'Foo<Number>'" "true"
trait Foo<out T: Number> {
fun foo(x: T)
}
fun bar(_x: Any) {
var x = _x
if (x is Foo<*>) {
x<caret>.foo(42)
}
}
@@ -0,0 +1,6 @@
// "Cast expression 'Foo<Number>()' to 'Foo<Int>'" "true"
class Foo<out T>
fun foo(): Foo<Int> {
return Foo<Number>()<caret>
}
@@ -0,0 +1,7 @@
// "Cast expression 'Foo<Number>()' to 'Foo<Int>'" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>Foo&lt;jet.Int&gt;</td></tr><tr><td>Found:</td><td>Foo&lt;jet.Number&gt;</td></tr></table></html>
class Foo<T>
fun foo(): Foo<Int> {
return Foo<Number>()
}
@@ -0,0 +1,9 @@
// "Cast expression 'a + a' to 'B'" "true"
trait A {
fun plus(x: Any): A
}
trait B : A
fun foo(a: A): B {
return a + a<caret>
}
@@ -0,0 +1,8 @@
// "Cast expression 'a: A' to 'B'" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>B</td></tr><tr><td>Found:</td><td>A</td></tr></table></html>
open class A
class B : A()
fun foo(a: A): B {
return a: A<caret>
}
@@ -0,0 +1,5 @@
// "Cast expression 'x' to 'String'" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.String</td></tr><tr><td>Found:</td><td>jet.Int</td></tr></table></html>
fun foo(x: Int) {
x<caret>: String
}