Generate parse error on label without name '@'

This commit is contained in:
Svetlana Isakova
2014-05-15 15:24:14 +04:00
parent f109cfc303
commit e0f37bbef0
15 changed files with 358 additions and 316 deletions
@@ -65,9 +65,9 @@ class C {
}
fun containsBreakInsideLoopWithLabel(a: String?, array: Array<Int>) {
@ while(a == null) {
@l while(a == null) {
for (el in array) {
break@
break@l
}
}
a<!UNSAFE_CALL!>.<!>compareTo("2")
@@ -75,10 +75,10 @@ class C {
fun unresolvedBreak(a: String?, array: Array<Int>) {
while(a == null) {
@ for (el in array) {
@l for (el in array) {
break
}
if (true) break else <!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@<!><!>
if (true) break else <!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@l<!><!>
}
a<!UNSAFE_CALL!>.<!>compareTo("2")
}
@@ -9,7 +9,7 @@ fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return<!>}
fun test2() : Any = @a {<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@a 1<!>}
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
fun test4(): ()-> Unit = { <!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return@test4<!> }
fun test5(): Any = @{ <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@<!> }
fun test5(): Any = @l{ <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l<!> }
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return 1<!>}
fun bbb() {
@@ -60,7 +60,7 @@ fun canBe(i0: Int, j: Int) {
(@label j) = <!UNUSED_VALUE!>34<!> //repeat for j
val a = A()
(@ a.a) = 3894
(@l a.a) = 3894
}
fun canBe2(j: Int) {
@@ -108,7 +108,7 @@ class Test() {
<!VAL_REASSIGNMENT!>b<!> += 34
a++
(@ a)++
(@l a)++
(a : Int)++
<!UNUSED_CHANGED_VALUE!>(a)++<!>
}
@@ -5,7 +5,7 @@ fun test() {
fun test1() {
val x = run(@{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 1<!>})
val x = run(@l{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 1<!>})
x: Int
}
@@ -0,0 +1,36 @@
fun foo(a: Any?): Int {
<!SYNTAX!>@<!>{ () : Unit ->
return<!SYNTAX!>@<!>
}
<!SYNTAX!>@<!> while(a == null) {
if (true) {
break<!SYNTAX!>@<!>
}
else {
continue<!SYNTAX!>@<!>
}
}
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!> = 1
(<!SYNTAX!>@<!> b) = <!UNUSED_VALUE!>2<!>
return<!SYNTAX!>@<!> 1
}
open class A {
fun foo() {}
}
class B : A() {
fun bar() {
this<!SYNTAX!>@<!>.foo()
super<!SYNTAX!>@<!>.foo()
}
}
fun bar(f: () -> Unit) = f
fun test() {
bar <!SYNTAX!>@<!>{}
}
@@ -9,8 +9,7 @@ fun main(args : Array<String>) {
val <!UNUSED_VARIABLE!>h1<!> : String = <!TYPE_MISMATCH!>--v<!>;
val <!UNUSED_VARIABLE!>i<!> : String = <!TYPE_MISMATCH!>!true<!>;
val <!UNUSED_VARIABLE!>j<!> : String = @foo <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>;
val <!UNUSED_VARIABLE!>j1<!> : String = @ <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>;
val <!UNUSED_VARIABLE!>j2<!> : String = @@ <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>;
val <!UNUSED_VARIABLE!>k<!> : String = <!TYPE_MISMATCH!>-1<!>;
val <!UNUSED_VARIABLE!>l<!> : String = <!TYPE_MISMATCH!>+1<!>;
val <!UNUSED_VARIABLE!>k<!> : String = @foo @bar <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>;
val <!UNUSED_VARIABLE!>l<!> : String = <!TYPE_MISMATCH!>-1<!>;
val <!UNUSED_VARIABLE!>m<!> : String = <!TYPE_MISMATCH!>+1<!>;
}
@@ -4,8 +4,8 @@ package kt411
fun f() {
invoker(
@{
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 11<!> // expects Function, but should expect Int
@l{
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 11<!> // expects Function, but should expect Int
}
)
}
@@ -13,15 +13,15 @@ fun invoker(<!UNUSED_PARAMETER!>gen<!> : () -> Int) : Int = 0
//more tests
fun t1() {
val <!UNUSED_VARIABLE!>v<!> = @{ () : Int ->
return@ 111
val <!UNUSED_VARIABLE!>v<!> = @l{ () : Int ->
return@l 111
}
}
fun t2() : String {
val <!UNUSED_VARIABLE!>g<!> : ()-> Int = @{
val <!UNUSED_VARIABLE!>g<!> : ()-> Int = @l{
if (true) {
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 1<!>
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 1<!>
}
<!RETURN_NOT_ALLOWED!>return "s"<!>
}
@@ -30,19 +30,19 @@ fun t2() : String {
fun t3() : String {
invoker(
@{
@l{
if (true) {
<!RETURN_NOT_ALLOWED!>return@t3 "1"<!>
}
else {
<!RETURN_NOT_ALLOWED!>return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!><!>
}
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 0<!>
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 0<!>
}
)
invoker(
@{ (): Int ->
return@ 1
@l{ (): Int ->
return@l 1
}
)
invoker(
@@ -57,8 +57,8 @@ fun t4() : Int {
val <!UNUSED_VARIABLE!>h<!> : ()-> String = @l{
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l "a"<!>
}
val <!UNUSED_VARIABLE!>g<!> : ()-> String = @{ () : String ->
return@ "a"
val <!UNUSED_VARIABLE!>g<!> : ()-> String = @l{ () : String ->
return@l "a"
}
fun inner(): String {