Autocasts for 'this' and stable qualified expressions

This commit is contained in:
Andrey Breslav
2011-10-18 22:30:28 +04:00
parent abbb31080f
commit 1b4bebaaf0
29 changed files with 1094 additions and 494 deletions
+2 -2
View File
@@ -189,11 +189,11 @@ fun tuples(a: Any?) {
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
}
if (a is String) {
val s: (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
}
fun illegalTupleReturnType(): (Any, String) = (<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
if (a is String) {
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
}
val illegalFunctionLiteral: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
@@ -0,0 +1,91 @@
namespace example;
namespace ns {
val y : Any? = 2
}
object Obj {
val y : Any? = 2
}
class AClass() {
class object {
val y : Any? = 2
}
}
val x : Any? = 1
fun Any?.vars(a: Any?) : Int {
var b: Int = 0
if (ns.y is Int) {
b = ns.y
}
if (ns.y is Int) {
b = example.ns.y
}
if (example.ns.y is Int) {
b = ns.y
}
if (example.ns.y is Int) {
b = example.ns.y
}
// if (namespace.bottles.ns.y is Int) {
// b = ns.y
// }
if (Obj.y is Int) {
b = Obj.y
}
if (example.Obj.y is Int) {
b = Obj.y
}
if (AClass.y is Int) {
b = AClass.y
}
if (example.AClass.y is Int) {
b = AClass.y
}
if (x is Int) {
b = x
}
if (example.x is Int) {
b = x
}
if (example.x is Int) {
b = example.x
}
return 1
}
fun Any?.foo() : Int {
if (this is Int)
return this
if (this@foo is Int)
return this
if (this@foo is Int)
return this@foo
if (this is Int)
return this@foo
return 1
}
trait T {}
open class C {
fun foo() {
var t : T? = null
if (this is T) {
t = this
}
if (this is T) {
t = this@C
}
if (this@C is T) {
t = this
}
if (this@C is T) {
t = this@C
}
}
}