Replace some FIR syntax errors with more proper diagnostics

This commit is contained in:
Mikhail Glukhikh
2020-03-24 19:33:34 +03:00
parent 2f63c8a46a
commit b27152f903
53 changed files with 339 additions and 320 deletions
+11 -11
View File
@@ -3,26 +3,26 @@ class C {
fun f (a : Boolean, b : Boolean) {
b@ while (true)
a@ {
break@f
<!NOT_A_LOOP_LABEL!>break@f<!>
break
break@b
break@a
<!NOT_A_LOOP_LABEL!>break@a<!>
}
continue
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>
b@ while (true)
a@ {
continue@f
<!NOT_A_LOOP_LABEL!>continue@f<!>
continue
continue@b
continue@a
<!NOT_A_LOOP_LABEL!>continue@a<!>
}
break
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>
continue@f
break@f
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@f<!>
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@f<!>
}
fun containsBreak(a: String?, b: String?) {
@@ -50,7 +50,7 @@ class C {
fun containsIllegalBreak(a: String?) {
loop@ while(a == null) {
break@label
<!NOT_A_LOOP_LABEL!>break@label<!>
}
a.compareTo("2")
}
@@ -78,7 +78,7 @@ class C {
l@ for (el in array) {
break
}
if (true) break else break@l
if (true) break else <!NOT_A_LOOP_LABEL!>break@l<!>
}
a.<!INAPPLICABLE_CANDIDATE!>compareTo<!>("2")
}
@@ -86,7 +86,7 @@ class C {
fun twoLabelsOnLoop() {
label1@ label2@ for (i in 1..100) {
if (i > 0) {
break@label1
<!NOT_A_LOOP_LABEL!>break@label1<!>
}
else {
break@label2
@@ -1,92 +0,0 @@
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
fun breakContinueInWhen(i: Int) {
for (y in 0..10) {
when(i) {
0 -> continue
1 -> break
2 -> {
for(z in 0..10) {
break
}
for(w in 0..10) {
continue
}
}
}
}
}
fun breakContinueInWhenWithWhile(i: Int, j: Int) {
while (i > 0) {
when (i) {
0 -> continue
1 -> break
2 -> {
while (j > 0) {
break
}
}
}
}
}
fun breakContinueInWhenWithDoWhile(i: Int, j: Int) {
do {
when (i) {
0 -> continue
1 -> break
2 -> {
do {
if (j == 5) break
if (j == 10) continue
} while (j > 0)
}
}
} while (i > 0)
}
fun labeledBreakContinue(i: Int) {
outer@ for (y in 0..10) {
when (i) {
0 -> continue@outer
1 -> break@outer
}
}
}
fun testBreakContinueInWhenInWhileCondition() {
var i = 0
while (
when (i) {
1 -> break
2 -> continue
else -> true
}
) {
++i
}
}
fun testBreakContinueInWhenInDoWhileCondition() {
var i = 0
do {
++i
} while (
when (i) {
1 -> break
2 -> continue
else -> true
}
)
}
fun testBreakContinueInWhenInForIteratorExpression(xs: List<Any>, i: Int) {
for (x in when (i) {
1 -> break
2 -> continue
else -> xs
}) {
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
fun breakContinueInWhen(i: Int) {
@@ -1,13 +1,13 @@
fun test(c : Char) {
test('')
test(<!ILLEGAL_CONST_EXPRESSION!>''<!>)
test('a')
test('aa')
<!INAPPLICABLE_CANDIDATE!>test<!>('a)
<!UNRESOLVED_REFERENCE!>test<!>('
<!UNRESOLVED_REFERENCE!>test<!>(0<!SYNTAX!><!>'
test(<!ILLEGAL_CONST_EXPRESSION!>'aa'<!>)
<!INAPPLICABLE_CANDIDATE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>'a)<!>
<!UNRESOLVED_REFERENCE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>'<!>
<!UNRESOLVED_REFERENCE!>test<!>(0<!ILLEGAL_CONST_EXPRESSION!><!SYNTAX!><!>'<!>
<!UNRESOLVED_REFERENCE!>test<!>('\n')
<!UNRESOLVED_REFERENCE!>test<!>('\\')
<!UNRESOLVED_REFERENCE!>test<!>(''<!SYNTAX!><!>'')
<!UNRESOLVED_REFERENCE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>''<!><!ILLEGAL_CONST_EXPRESSION!><!SYNTAX!><!>''<!>)
test('\'')
test('\"')
}
@@ -2,11 +2,11 @@
// KT-451 Incorrect character literals cause assertion failures
fun ff() {
val b = ''
val c = '23'
val d = 'a
val e = 'ab
val f = '\'
val b = <!ILLEGAL_CONST_EXPRESSION!>''<!>
val c = <!ILLEGAL_CONST_EXPRESSION!>'23'<!>
val d = <!ILLEGAL_CONST_EXPRESSION!>'a<!>
val e = <!ILLEGAL_CONST_EXPRESSION!>'ab<!>
val f = <!ILLEGAL_CONST_EXPRESSION!>'\'<!>
}
fun test() {
@@ -19,19 +19,19 @@ fun test() {
'\''
'\\'
'\$'
'\x'
'\123'
'\ra'
'\000'
'\000'
<!ILLEGAL_CONST_EXPRESSION!>'\x'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\123'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\ra'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\000'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\000'<!>
'\u0000'
'\u000a'
'\u000A'
'\u'
'\u0'
'\u00'
'\u000'
'\u000z'
'\\u000'
'\'
<!ILLEGAL_CONST_EXPRESSION!>'\u'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\u0'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\u00'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\u000'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\u000z'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\\u000'<!>
<!ILLEGAL_CONST_EXPRESSION!>'\'<!>
}
+16 -16
View File
@@ -14,7 +14,7 @@ class C() : B() {
this.c = 34
super.c = 3535 //repeat for 'c'
getInt() = 12
<!VARIABLE_EXPECTED!>getInt()<!> = 12
}
fun foo1(c: C) {
@@ -42,27 +42,27 @@ fun cannotBe() {
var i: Int = 5
<!UNRESOLVED_REFERENCE!>z<!> = 30;
"" = "";
foo() = Unit;
<!VARIABLE_EXPECTED!>""<!> = "";
<!VARIABLE_EXPECTED!>foo()<!> = Unit;
(i as Int) = 34
(i is Int) = false
A() = A()
5 = 34
(<!VARIABLE_EXPECTED!>i as Int<!>) = 34
(<!VARIABLE_EXPECTED!>i is Int<!>) = false
<!VARIABLE_EXPECTED!>A()<!> = A()
<!VARIABLE_EXPECTED!>5<!> = 34
}
fun canBe(i0: Int, j: Int) {
var i = i0
(label@ i) = 34
(<!VARIABLE_EXPECTED!>label@ i<!>) = 34
(label@ j) = 34 //repeat for j
(<!VARIABLE_EXPECTED!>label@ j<!>) = 34 //repeat for j
val a = A()
(l@ a.a) = 3894
(<!VARIABLE_EXPECTED!>l@ a.a<!>) = 3894
}
fun canBe2(j: Int) {
(label@ j) = 34
(<!VARIABLE_EXPECTED!>label@ j<!>) = 34
}
class A() {
@@ -77,11 +77,11 @@ class Test() {
<!VARIABLE_EXPECTED!>getInt()<!> += 343
(f@ <!VARIABLE_EXPECTED!>getInt()<!>) += 343
1++
(r@ 1)++
<!VARIABLE_EXPECTED!>1<!>++
(<!VARIABLE_EXPECTED!>r@ 1<!>)++
getInt()++
(m@ getInt())++
<!VARIABLE_EXPECTED!>getInt()<!>++
(<!VARIABLE_EXPECTED!>m@ getInt()<!>)++
this<!UNRESOLVED_REFERENCE!>++<!>
@@ -106,7 +106,7 @@ class Test() {
<!VARIABLE_EXPECTED!>b<!> += 34
a++
(l@ a)++
(<!VARIABLE_EXPECTED!>l@ a<!>)++
(a)++
}
@@ -1,24 +1,24 @@
object A1() {
constructor(x: Int = "", y: Int) : this() {
object A1<!CONSTRUCTOR_IN_OBJECT!>()<!> {
<!CONSTRUCTOR_IN_OBJECT!>constructor(x: Int = "", y: Int)<!> : this() {
x + y
}
}
object A2 public constructor(private val prop: Int) {
constructor(x: Int = "", y: Int) : this(x * y) {
object A2 public <!CONSTRUCTOR_IN_OBJECT!>constructor(private val prop: Int)<!> {
<!CONSTRUCTOR_IN_OBJECT!>constructor(x: Int = "", y: Int)<!> : this(x * y) {
x + y
}
}
val x = object (val prop: Int) {
<!CONSTRUCTOR_IN_OBJECT, CONSTRUCTOR_IN_OBJECT!>constructor()<!> : <!UNRESOLVED_REFERENCE!>this<!>(1) {
val x = object <!CONSTRUCTOR_IN_OBJECT!>(val prop: Int)<!> {
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!> : <!UNRESOLVED_REFERENCE!>this<!>(1) {
val x = 1
x * x
}
}
class A3 {
companion object B(val prop: Int) {
public constructor() : this(2)
companion object B<!CONSTRUCTOR_IN_OBJECT!>(val prop: Int)<!> {
public <!CONSTRUCTOR_IN_OBJECT!>constructor()<!> : this(2)
}
}
@@ -11,7 +11,7 @@ fun test(a: Any) {
a foo"asd${a}sfsa"
a foo"""sdf"""
a foo'd'
a foo''
a foo<!ILLEGAL_CONST_EXPRESSION!>''<!>
a foo""foo a
a foo"asd"foo a
@@ -19,17 +19,17 @@ fun test(a: Any) {
a foo"asd${a}sfsa"foo a
a foo"""sdf"""foo a
a foo'd'foo a
a foo''foo a
a foo<!ILLEGAL_CONST_EXPRESSION!>''<!>foo a
a in"foo"
a in"""foo"""
a in's'
a in''
a in<!ILLEGAL_CONST_EXPRESSION!>''<!>
a !in"foo"
a !in"""foo"""
a !in's'
a !in''
a !in<!ILLEGAL_CONST_EXPRESSION!>''<!>
if("s"is Any) {}
if("s"is Any) {}
@@ -9,7 +9,7 @@ interface T2 constructor() {}
interface T3 private constructor(a: Int) {}
interface T4 {
constructor(a: Int) {
<!CONSTRUCTOR_IN_INTERFACE!>constructor(a: Int)<!> {
val b: Int = 1
}
}
@@ -18,4 +18,4 @@ class G {
companion object F<T>
}
object H<T, R>()
object H<T, R><!CONSTRUCTOR_IN_OBJECT!>()<!>
@@ -9,7 +9,7 @@ annotation class Foo(
annotation class Bar(
val a: Array<String> = [' '],
val b: Array<String> = ["", ''],
val b: Array<String> = ["", <!ILLEGAL_CONST_EXPRESSION!>''<!>],
val c: Array<String> = [1]
)
@@ -1,17 +1,17 @@
fun test() {
l@ for (i in if (true) 1..10 else continue@l) {}
for (i in if (true) 1..10 else continue) {}
l@ for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@l<!>) {}
for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
while (break) {}
l@ while (break@l) {}
while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>) {}
l@ while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@l<!>) {}
do {} while (continue)
l@ do {} while (continue@l)
do {} while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>)
l@ do {} while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@l<!>)
//KT-5704
var i = 0
while (if(i++ == 10) break else continue) {}
while (if(i++ == 10) <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!> else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
}
fun test2(b: Boolean) {
@@ -1,5 +1,5 @@
fun foo1() = while (b()) {}
fun foo1() = <!EXPRESSION_REQUIRED!>while (b()) {}<!>
fun foo2() = <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (i in 10) {}<!>
@@ -19,7 +19,7 @@ class Test3 {
}
fun test4() {
break@test4
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@test4<!>
}
class Test5 {
@@ -43,11 +43,11 @@ class Test6 {
class Test7 {
fun Test7() {
Test8@ while (true) {
break@Test7
<!NOT_A_LOOP_LABEL!>break@Test7<!>
}
Test7@ while (true) {
break@Test8
<!NOT_A_LOOP_LABEL!>break@Test8<!>
}
}
}
@@ -15,7 +15,7 @@ fun main() {
}
//KT-351 Distinguish statement and expression positions
val w = while (true) {}
val w = <!EXPRESSION_REQUIRED!>while (true) {}<!>
fun foo() {
var z = 2
@@ -152,12 +152,12 @@ fun bar(a: Unit) {}
fun testStatementInExpressionContext() {
var z = 34
val a1: Unit = z = 334
val a1: Unit = <!EXPRESSION_REQUIRED!>z = 334<!>
val f = for (i in 1..10) {}
if (true) return z = 34
return while (true) {}
if (true) return <!EXPRESSION_REQUIRED!>z = 34<!>
return <!EXPRESSION_REQUIRED!>while (true) {}<!>
}
fun testStatementInExpressionContext2() {
val a2: Unit = while(true) {}
val a2: Unit = <!EXPRESSION_REQUIRED!>while(true) {}<!>
}
@@ -1 +1 @@
data object Object(val x: Int, val y: Int)
data object Object<!CONSTRUCTOR_IN_OBJECT!>(val x: Int, val y: Int)<!>
@@ -4,7 +4,7 @@
fun foo(block: () -> (() -> Int)) {}
fun test() {
val x = fun named1(x: Int): Int { return 1 }
val x = <!EXPRESSION_REQUIRED!>fun named1(x: Int): Int { return 1 }<!>
x <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Function1<Int, Int>>() }
foo { fun named2(): Int {return 1} }
@@ -45,12 +45,12 @@ fun test() {
x4 checkType { <!UNRESOLVED_REFERENCE!>_<!><Function1<Int, Unit>>() }
{ y: Int -> fun named14(): Int {return 1} }
val b = <!UNRESOLVED_REFERENCE!>(fun named15(): Boolean { return true })()<!>
val b = <!UNRESOLVED_REFERENCE!>(<!EXPRESSION_REQUIRED!>fun named15(): Boolean { return true }<!>)()<!>
baz(fun named16(){})
baz(<!EXPRESSION_REQUIRED!>fun named16(){}<!>)
}
fun bar() = fun named() {}
fun bar() = <!EXPRESSION_REQUIRED!>fun named() {}<!>
fun <T> run(block: () -> T): T = null!!
fun run2(block: () -> Unit): Unit = null!!
@@ -1,7 +1,7 @@
enum class E public constructor(val x: Int) {
enum class E <!NON_PRIVATE_CONSTRUCTOR_IN_ENUM!>public constructor(val x: Int)<!> {
FIRST();
internal constructor(): this(42)
<!NON_PRIVATE_CONSTRUCTOR_IN_ENUM!>internal constructor(): this(42)<!>
constructor(y: Int, z: Int): this(y + z)
}
@@ -5,5 +5,5 @@ fun foo() {
fun A.foo() {}
(fun A.foo() {})
run(fun foo() {})
run(<!EXPRESSION_REQUIRED!>fun foo() {}<!>)
}
@@ -6,12 +6,12 @@ fun foo(i: Int) = i
fun bar(l: Long) = l
fun main() {
val i = <!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>111111111111111777777777777777<!>
val i = <!ILLEGAL_CONST_EXPRESSION!>111111111111111777777777777777<!>
//todo add diagnostic text messages
//report only 'The value is out of range'
//not 'An integer literal does not conform to the expected type Int/Long'
val l: Long = <!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>1111111111111117777777777777777<!>
foo(<!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
bar(<!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
val l: Long = <!ILLEGAL_CONST_EXPRESSION!>1111111111111117777777777777777<!>
foo(<!ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
bar(<!ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
}
@@ -8,5 +8,5 @@ operator fun RemAndRemAssign.remAssign(x: Int) {}
fun test() {
var c = RemAndRemAssign
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c %= 1<!>
<!ASSIGN_OPERATOR_AMBIGUITY!>c %= 1<!>
}
@@ -11,7 +11,7 @@ fun test(m: MyInt) {
m += m
var i = 1
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>i += 34<!>
<!ASSIGN_OPERATOR_AMBIGUITY!>i += 34<!>
}
@@ -9,5 +9,5 @@ fun test() {
val c = C()
c += ""
var c1 = C()
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c1 += ""<!>
<!ASSIGN_OPERATOR_AMBIGUITY!>c1 += ""<!>
}
@@ -15,5 +15,5 @@ fun test() {
val c = C()
c.c += ""
var c1 = C1()
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c1.c += ""<!>
<!ASSIGN_OPERATOR_AMBIGUITY!>c1.c += ""<!>
}
@@ -13,11 +13,11 @@ fun box() : Boolean {
var c = A()
val d = c;
c %= A();
return (c != d) && (c.p = "yeah")
return (c != d) && <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!>
}
fun box2() : Boolean {
var c = A()
return (c.p = "yeah") && true
return <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!> && true
}
@@ -1,7 +1,7 @@
sealed class Sealed protected constructor(val x: Int) {
sealed class Sealed <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(val x: Int)<!> {
object FIRST : Sealed()
public constructor(): this(42)
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public constructor(): this(42)<!>
constructor(y: Int, z: Int): this(y + z)
}
@@ -1,17 +1,17 @@
object A {
constructor()
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
init {}
}
enum class B {
X() {
<!UNRESOLVED_REFERENCE!>constructor()<!>
<!CONSTRUCTOR_IN_OBJECT, UNRESOLVED_REFERENCE!>constructor()<!>
}
}
class C {
companion object {
constructor()
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
}
}
@@ -1,3 +0,0 @@
interface A {
constructor()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
<!CONSTRUCTOR_IN_INTERFACE!>constructor()<!>
}
@@ -4,7 +4,7 @@ fun <T : CharSequence> foo(x: Array<Any>, block: (T, Int) -> Int) {
@Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int)
// to prevent unused assignment diagnostic for the above statement
r.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
r.hashCode()
var i = 1