JET-34 Require a return statement in a function with a block body

JET-77 Require a return type annotation for non-Unit returning functions with block bodies
This commit is contained in:
Andrey Breslav
2011-06-17 18:03:30 +04:00
parent c4eecea575
commit 94f00509e2
17 changed files with 303 additions and 144 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ fun <T, E> T.foo(x : E, y : A) : T {
this<warning>?.</warning>minus<T>(this)
this
return this
}
class A
+19 -5
View File
@@ -5,6 +5,19 @@ fun unitEmpty() : Unit {}
fun unitEmptyReturn() : Unit {return}
fun unitIntReturn() : Unit {return <error>1</error>}
fun unitUnitReturn() : Unit {return ()}
fun test1() : Any = {<error>return</error>}
fun test2() : Any = @a {return@a 1}
fun test3() : Any { <error>return</error> }
fun foo(expr: StringBuilder): Int {
val c = 'a'
when(c) {
'\0' => throw Exception("zero")
else => throw Exception("nonzero" + c)
}
}
fun unitShort() : Unit = ()
fun unitShortConv() : Unit = 1
fun unitShortNull() : Unit = null
@@ -13,7 +26,8 @@ fun intEmpty() : Int <error>{}</error>
fun intShortInfer() = 1
fun intShort() : Int = 1
//fun intBlockInfer() {1}
fun intBlock() : Int {1}
fun intBlock() : Int {return 1}
fun intBlock() : Int {<error>1</error>}
fun blockReturnUnitMismatch() : Int {<error>return</error>}
fun blockReturnValueTypeMismatch() : Int {return <error>3.4</error>}
@@ -40,7 +54,7 @@ fun blockAndAndMismatch() : Int {
<error>(return <error>true</error>) || (return <error>false</error>)</error>
}
fun blockReturnValueTypeMatch() : Int {
return if (1 > 2) <error>1.0</error> else <error>2.0</error>
return <error>if (1 > 2) 1.0 else 2.0</error>
}
fun blockReturnValueTypeMatch() : Int {
return <error>if (1 > 2) 1</error>
@@ -79,7 +93,7 @@ fun blockReturnValueTypeMatch() : Int {
<error>1.0</error></error>
}
fun blockReturnValueTypeMatch() : Int {
<error>if (1 > 2)
return <error>if (1 > 2)
1</error>
}
fun blockReturnValueTypeMatch() : Int {
@@ -88,6 +102,6 @@ fun blockReturnValueTypeMatch() : Int {
}
fun blockReturnValueTypeMatch() : Int {
if (1 > 2)
1
else <error>1.0</error>
return 1
else return <error>1.0</error>
}
+1 -1
View File
@@ -29,7 +29,7 @@ namespace closures {
val y = this@A : A
val z = this : B
val Int.xx = this : Int
fun Char.xx() {
fun Char.xx() : Any {
this : Char
val a = {Double.() => this : Double + this@xx : Char}
val b = @a{Double.() => this@a : Double + this@xx : Char}
+11 -11
View File
@@ -58,7 +58,7 @@ fun t4break(a : Boolean) : Int {
break
}
while (<error>a</error>)
1
return 1
}
fun t5() : Int {
@@ -67,7 +67,7 @@ fun t5() : Int {
<error>2</error>
}
while (<error>1 > 2</error>)
<error>1</error>
<error>return 1</error>
}
fun t6() : Int {
@@ -75,7 +75,7 @@ fun t6() : Int {
return 1
<error>2</error>
}
1
return 1
}
fun t6break() : Int {
@@ -83,7 +83,7 @@ fun t6break() : Int {
break
<error>2</error>
}
1
return 1
}
fun t7(b : Int) : Int {
@@ -91,7 +91,7 @@ fun t7(b : Int) : Int {
return 1
<error>2</error>
}
1
return 1
}
fun t7break(b : Int) : Int {
@@ -99,7 +99,7 @@ fun t7break(b : Int) : Int {
return 1
<error>2</error>
}
1
return 1
}
fun t7() : Int {
@@ -110,7 +110,7 @@ fun t7() : Int {
catch (e : Any) {
2
}
1 // this is OK, like in Java
return 1 // this is OK, like in Java
}
fun t8() : Int {
@@ -122,24 +122,24 @@ fun t8() : Int {
return 1
<error>2</error>
}
<error>1</error>
<error>return 1</error>
}
fun blockAndAndMismatch() : Boolean {
<error>(return true) || (return false)</error>
<error>true</error>
<error>return true</error>
}
fun tf() : Int {
try {<error>return 1</error>} finally{return 1}
<error>1</error>
<error>return 1</error>
}
fun failtest(a : Int) : Int {
<error>if (fail() || true) {
}</error>
<error>1</error>
<error>return 1</error>
}
fun foo(a : Nothing) : Unit {
+1 -1
View File
@@ -16,7 +16,7 @@ fun foo() : Int {
<warning>?.</warning>equals(1) => 1
else => 1
}
when (<warning>x</warning>?:null) {
return when (<warning>x</warning>?:null) {
<error>.</error>equals(1) => 1
?.equals(1).equals(2) => 1
}
@@ -14,9 +14,9 @@ class Test() {
val c3 : Int
<info>get</info>() { return 1 }
val c4 : Int
<info>get</info>() { 1 }
<info>get</info>() = 1
val <info>c5</info> : Int
<info>get</info>() { $c5 + 1 }
<info>get</info>() = $c5 + 1
<info>abstract</info> var y : Int
<info>abstract</info> var y1 : Int <info>get</info>
@@ -29,5 +29,5 @@ fun box() : String {
val p4 = P4(240, y)
if (p4.x + p4.y != 239) return "FAIL #7"
"OK"
return "OK"
}
@@ -5,5 +5,5 @@ fun concat(l: List<String>): String? {
for(s in l) {
sb.append(s)
}
sb.toString()
return sb.toString()
}
@@ -3,5 +3,5 @@ fun concat(l: Array<String>): String? {
for(s in l) {
sb.append(s)
}
sb.toString()
return sb.toString()
}
+1 -1
View File
@@ -2,5 +2,5 @@ fun f(a:Int) : Int {
val x = 42
val y = 50
y
return y
}