Report RETURN_NOT_ALLOWED and RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY only on the return with label (KT-13340)

#KT-13340 Fixed
This commit is contained in:
Nikolay Krasko
2016-08-04 13:29:44 +03:00
parent 95ea191442
commit 300e0acd27
21 changed files with 70 additions and 32 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ fun test2() : Any = a@ {return@a 1}
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
fun test4(): ()-> Unit = { <!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return@test4<!> }
fun test5(): Any = l@{ return@l }
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return 1<!>}
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return<!> 1}
fun bbb() {
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
@@ -136,7 +136,7 @@ fun blockNoReturnIfUnitInOneBranch(): Int {
fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!>
fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2
val a = <!RETURN_NOT_ALLOWED!>return 1<!>
val a = <!RETURN_NOT_ALLOWED!>return<!> 1
class A() {
}
@@ -0,0 +1,3 @@
fun foo1(): () -> String = <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> { "some long expression "}
fun foo2(): () -> String = <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!UNRESOLVED_REFERENCE!>@label<!><!> { "some long expression "}
fun foo3(): () -> String = <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!><!SYNTAX!>@<!> { "some long expression "}
@@ -0,0 +1,5 @@
package
public fun foo1(): () -> kotlin.String
public fun foo2(): () -> kotlin.String
public fun foo3(): () -> kotlin.String
@@ -1,6 +1,6 @@
fun find2(): Any? {
fun visit(element: Any) {
<!RETURN_NOT_ALLOWED!>return@find2 element<!>
<!RETURN_NOT_ALLOWED!>return@find2<!> element
}
return null
}
@@ -10,7 +10,7 @@ fun find2(): Any? {
fun find(): Any? {
object : Any() {
fun visit(element: Any) {
<!RETURN_NOT_ALLOWED!>return@find element<!>
<!RETURN_NOT_ALLOWED!>return@find<!> element
}
}
return null
@@ -18,7 +18,7 @@ fun find(): Any? {
fun find4(): Any? {
<!NOT_YET_SUPPORTED_IN_INLINE!>inline fun visit(element: Any) {
<!RETURN_NOT_ALLOWED!>return@find4 element<!>
<!RETURN_NOT_ALLOWED!>return@find4<!> element
}<!>
return null
}
@@ -26,7 +26,7 @@ fun find4(): Any? {
fun find3(): Any? {
object : Any() {
<!NOTHING_TO_INLINE!>inline<!> fun visit(element: Any) {
<!RETURN_NOT_ALLOWED!>return@find3 element<!>
<!RETURN_NOT_ALLOWED!>return@find3<!> element
}
}
return null
@@ -12,9 +12,9 @@ fun test() {
doSmth(if (true) 3 else return, <!TOO_MANY_ARGUMENTS!>1<!>)
}
val a : Nothing = <!RETURN_NOT_ALLOWED!>return 1<!>
val a : Nothing = <!RETURN_NOT_ALLOWED!>return<!> 1
val b = <!RETURN_NOT_ALLOWED!>return 1<!>
val b = <!RETURN_NOT_ALLOWED!>return<!> 1
val c = doSmth(if (true) 3 else <!RETURN_NOT_ALLOWED!>return<!>)
@@ -1,34 +1,34 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// KT-5068 Add special error for scala-like syntax 'fun foo(): Int = { 1 }'
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
fun outer() {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
}
class Outer {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
class Nested {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
@@ -1,7 +1,7 @@
fun f() {
foo {
bar {
<!RETURN_NOT_ALLOWED!>return@foo 1<!>
<!RETURN_NOT_ALLOWED!>return@foo<!> 1
}
return@foo 1
}
@@ -17,7 +17,7 @@ inline fun inlineFun(s: ()->Int) {
fun noInlineCall(): String {
noInline {
if (true) {
<!RETURN_NOT_ALLOWED!>return@noInlineCall ""<!>
<!RETURN_NOT_ALLOWED!>return@noInlineCall<!> ""
}
1
}
@@ -1,6 +1,6 @@
fun box() : String {
test {
<!RETURN_NOT_ALLOWED!>return@box "123"<!>
<!RETURN_NOT_ALLOWED!>return@box<!> "123"
}
return "OK"
@@ -1,6 +1,6 @@
fun box() : String {
test {
<!RETURN_NOT_ALLOWED!>return@box "123"<!>
<!RETURN_NOT_ALLOWED!>return@box<!> "123"
}
return "OK"
@@ -7,7 +7,7 @@ inline fun <R> doCallInt(p: () -> R): R {
}
class A {
var result: Int = doCallInt { <!RETURN_NOT_ALLOWED!>return this<!> };
var result: Int = doCallInt { <!RETURN_NOT_ALLOWED!>return<!> this };
var field: Int
get() {
+1 -1
View File
@@ -2,7 +2,7 @@ fun nonlocals(b : Boolean) {
a@<!UNUSED_LAMBDA_EXPRESSION!>{
fun foo() {
if (b) {
<!RETURN_NOT_ALLOWED!>return@a 1<!> // The label must be resolved, but an error should be reported for a non-local return
<!RETURN_NOT_ALLOWED!>return@a<!> 1 // The label must be resolved, but an error should be reported for a non-local return
}
}
+4 -4
View File
@@ -23,7 +23,7 @@ fun t2() : String {
if (true) {
return@l 1
}
<!RETURN_NOT_ALLOWED!>return "s"<!>
<!RETURN_NOT_ALLOWED!>return<!> "s"
}
return "s"
}
@@ -32,10 +32,10 @@ fun t3() : String {
invoker(
l@{
if (true) {
<!RETURN_NOT_ALLOWED!>return@t3 "1"<!>
<!RETURN_NOT_ALLOWED!>return@t3<!> "1"
}
else {
<!RETURN_NOT_ALLOWED!>return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!><!>
<!RETURN_NOT_ALLOWED!>return<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>
}
<!UNREACHABLE_CODE!>return@l 0<!>
}
@@ -47,7 +47,7 @@ fun t3() : String {
)
invoker(
{
<!RETURN_NOT_ALLOWED!>return "0"<!>
<!RETURN_NOT_ALLOWED!>return<!> "0"
}
)
return "2"
@@ -1,7 +1,7 @@
class A {
init {
<!RETURN_NOT_ALLOWED!>return<!>
<!RETURN_NOT_ALLOWED, UNREACHABLE_CODE!>return 1<!>
<!UNREACHABLE_CODE!><!RETURN_NOT_ALLOWED!>return<!> 1<!>
}
constructor() <!UNREACHABLE_CODE!>{
if (1 == 1) {