GreatSyntacticShift: Syntax for function types, function literals, when and tuples
Bug:
fun loop(var times : Int) {
while(times > 0) {
val u : (value : Int) -> Unit = { // This arrow is confusing the lookahead
System.out?.println(it)
}
u(times--)
}
}
This commit is contained in:
+20
-20
@@ -1,4 +1,4 @@
|
||||
namespace kt770_351_735
|
||||
package kt770_351_735
|
||||
|
||||
//+JDK
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace kt770_351_735
|
||||
fun main(args : Array<String>) {
|
||||
var i = 0
|
||||
when (i) {
|
||||
1 => i--
|
||||
2 => i = 2 // i is surrounded by a black border
|
||||
else => <!UNRESOLVED_REFERENCE!>j<!> = 2
|
||||
1 -> i--
|
||||
2 -> i = 2 // i is surrounded by a black border
|
||||
else -> <!UNRESOLVED_REFERENCE!>j<!> = 2
|
||||
}
|
||||
System.out?.println(i)
|
||||
}
|
||||
@@ -26,8 +26,8 @@ fun foo() {
|
||||
z = <!UNUSED_VALUE!>34<!>
|
||||
}
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>f<!>: fun(): Int = <!TYPE_MISMATCH!>r<!>
|
||||
val <!UNUSED_VARIABLE!>g<!>: fun(): Any = r
|
||||
val <!UNUSED_VARIABLE!>f<!>: ()-> Int = <!TYPE_MISMATCH!>r<!>
|
||||
val <!UNUSED_VARIABLE!>g<!>: ()-> Any = r
|
||||
}
|
||||
|
||||
//KT-735 Statements without braces are prohibited on the right side of when entries.
|
||||
@@ -35,8 +35,8 @@ fun box() : Int {
|
||||
val d = 2
|
||||
var z = 0
|
||||
when(d) {
|
||||
is 5, is 3 => z++
|
||||
else => z = -1000
|
||||
is 5, is 3 -> z++
|
||||
else -> z = -1000
|
||||
}
|
||||
return z
|
||||
}
|
||||
@@ -47,10 +47,10 @@ fun test1() = while(true) {}
|
||||
fun test2(): Unit = while(true) {}
|
||||
|
||||
fun testCoercionToUnit() {
|
||||
val <!UNUSED_VARIABLE!>simple<!>: fun(): Unit = {
|
||||
val <!UNUSED_VARIABLE!>simple<!>: ()-> Unit = {
|
||||
41
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>withIf<!>: fun(): Unit = {
|
||||
val <!UNUSED_VARIABLE!>withIf<!>: ()-> Unit = {
|
||||
if (true) {
|
||||
3
|
||||
} else {
|
||||
@@ -58,16 +58,16 @@ fun testCoercionToUnit() {
|
||||
}
|
||||
}
|
||||
val i = 34
|
||||
val <!UNUSED_VARIABLE!>withWhen<!> : fun() : Unit = {
|
||||
val <!UNUSED_VARIABLE!>withWhen<!> : () -> Unit = {
|
||||
when(i) {
|
||||
is 1 => {
|
||||
is 1 -> {
|
||||
val d = 34
|
||||
"1"
|
||||
doSmth(d)
|
||||
|
||||
}
|
||||
is 2 => '4'
|
||||
else => true
|
||||
is 2 -> '4'
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ fun testCoercionToUnit() {
|
||||
45
|
||||
}
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>f<!> : fun() : String = <!TYPE_MISMATCH!>checkType<!>
|
||||
val <!UNUSED_VARIABLE!>f<!> : () -> String = <!TYPE_MISMATCH!>checkType<!>
|
||||
}
|
||||
|
||||
fun doSmth(<!UNUSED_PARAMETER!>i<!>: Int) {}
|
||||
@@ -88,16 +88,16 @@ fun testImplicitCoercion() {
|
||||
val d = 21
|
||||
var z = 0
|
||||
var <!UNUSED_VARIABLE!>i<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>when(d) {
|
||||
is 3 => null
|
||||
is 4 => { val <!NAME_SHADOWING, UNUSED_VARIABLE!>z<!> = 23 }
|
||||
else => z = 20
|
||||
is 3 -> null
|
||||
is 4 -> { val <!NAME_SHADOWING, UNUSED_VARIABLE!>z<!> = 23 }
|
||||
else -> z = 20
|
||||
}<!>
|
||||
|
||||
var <!UNUSED_VARIABLE!>u<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>when(d) {
|
||||
is 3 => {
|
||||
is 3 -> {
|
||||
z = <!UNUSED_VALUE!>34<!>
|
||||
}
|
||||
else => <!UNUSED_CHANGED_VALUE!>z--<!>
|
||||
else -> <!UNUSED_CHANGED_VALUE!>z--<!>
|
||||
}<!>
|
||||
|
||||
var <!UNUSED_VARIABLE!>iff<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>if (true) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace kt786
|
||||
package kt786
|
||||
|
||||
//KT-786 Exception on incomplete code with 'when'
|
||||
fun foo() : Int {
|
||||
val d = 2
|
||||
var z = 0
|
||||
when(d) {
|
||||
is 5, is 3 => <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, UNUSED_CHANGED_VALUE!>z++<!>
|
||||
<!ELSE_MISPLACED_IN_WHEN!>else => { <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>z = <!UNUSED_VALUE!>-1000<!><!> }<!>
|
||||
return z => <!UNREACHABLE_CODE!>34<!>
|
||||
is 5, is 3 -> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, UNUSED_CHANGED_VALUE!>z++<!>
|
||||
<!ELSE_MISPLACED_IN_WHEN!>else -> { <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>z = <!UNUSED_VALUE!>-1000<!><!> }<!>
|
||||
return z -> <!UNREACHABLE_CODE!>34<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ fun foo() : Int {
|
||||
fun fff(): Int {
|
||||
var d = 3
|
||||
when(d) {
|
||||
is 4 => 21
|
||||
return 2 => <!UNREACHABLE_CODE!>return 47<!>
|
||||
<!UNREACHABLE_CODE!>bar()<!> => <!UNREACHABLE_CODE!>45<!>
|
||||
<!UNREACHABLE_CODE!>444<!> => <!UNREACHABLE_CODE!>true<!>
|
||||
is 4 -> 21
|
||||
return 2 -> <!UNREACHABLE_CODE!>return 47<!>
|
||||
<!UNREACHABLE_CODE!>bar()<!> -> <!UNREACHABLE_CODE!>45<!>
|
||||
<!UNREACHABLE_CODE!>444<!> -> <!UNREACHABLE_CODE!>true<!>
|
||||
}
|
||||
return 34
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user