added visitor with type parameters (TypeInferrerVisitor now implements it);

added expected type (pass it down the psi tree);
added information about is-checks to type enrichment
This commit is contained in:
svtk
2011-08-16 15:52:56 +04:00
parent ad5e3abbb4
commit 57db9b076a
107 changed files with 1767 additions and 566 deletions
+58
View File
@@ -0,0 +1,58 @@
namespace automatic_casts
fun toInt(i: Int?): Int = if (i != null) i else 0
fun illegalWhenBody(a: Any): Int = when(a) {
is Int => a
is String => <error>a</error>
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int => return a
is String => return <error>a</error>
}
}
fun declarations(a: Any?) {
if (a is String) {
val p4: (Int, String) = (2, a)
}
if (a is String?) {
if (a != null) {
val s: String = a
}
}
if (a != null) {
if (a is String?) {
val s: String = a
}
}
}
fun tuples(a: Any?) {
if (a != null) {
val s: (Any, String) = (a, <error>a</error>)
}
if (a is String) {
val s: (Any, String) = (a, a)
}
fun illegalTupleReturnType(): (Any, String) = (<error>a</error>, <error>a</error>)
if (a is String) {
fun legalTupleReturnType(): (Any, String) = (a, a)
}
val illegalFunctionLiteral: Function0<Int> = <error>{ <error>a</error> }</error>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error>a</error> }
if (a is Int) {
val legalFunctionLiteral: Function0<Int> = { a }
val alsoLegalFunctionLiteral: Function0<Int> = { (): Int => a }
}
}
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
if (a is Int) return { a }
else return { 1 }
}
fun returnFunctionLiteral(a: Any?): Function0<Int> =
if (a is Int) { (): Int => a }
else { () => 1 }
fun illegalTupleReturnType(a: Any): (Any, String) = (a, <error>a</error>)
fun declarationInsidePattern(x: (Any, Any)): String = when(x) { is (val a is String, *) => a; else => "something" }
+25 -2
View File
@@ -61,7 +61,7 @@ fun blockAndAndMismatch() : Int {
<error>(return <error>true</error>) || (return <error>false</error>)</error>
}
fun blockReturnValueTypeMatch() : Int {
return <error>if (1 > 2) 1.0 else 2.0</error>
return if (1 > 2) <error>1.0</error> else <error>2.0</error>
}
fun blockReturnValueTypeMatch() : Int {
return <error>if (1 > 2) 1</error>
@@ -138,4 +138,27 @@ class A() {
return <error>1</error>
}
}
}
fun illegalConstantBody(): Int = <error>"s"</error>
fun illegalConstantBlock(): String {
return <error>1</error>
}
fun illegalIfBody(): Int =
if (1 < 2) <error>'a'</error> else { <error>1.0</error> }
fun illegalIfBlock(): Boolean {
if (1 < 2)
return false
else { return <error>1</error> }
}
fun illegalReturnIf(): Char {
return if (1 < 2) 'a' else { <error>1</error> }
}
fun returnNothing(): Nothing {
throw 1
}
fun f(): Int {
if (1 < 2) { return 1 } else returnNothing()
}
fun f(): Int = if (1 < 2) 1 else returnNothing()
+30
View File
@@ -0,0 +1,30 @@
namespace unresolved
fun testGenericArgumentsCount() {
val p1: Tuple2<error><Int></error> = (2, 2)
val p2: <error>Tuple2</error> = (2, 2)
}
fun testUnresolved() {
if (<error>a</error> is String) {
val s = <error>a</error>
}
<error>foo</error>(<error>a</error>)
val s = "s"
<error>foo</error>(s)
foo1(<error>i</error>)
s.<error>foo</error>()
when(<error>a</error>) {
is Int => <error>a</error>
is String => <error>a</error>
}
//TODO
for (j in <error>collection</error>) {
val i: Int = j
j += 1
}
}
fun foo1(i: Int) {}