From 798fe9b7d11add915e07d563e6057d19995e9266 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 16 Apr 2020 12:23:53 +0300 Subject: [PATCH] FIR: Adjust testData for spec tests: statements --- .../operator-assignments/p-2/neg/1.1.fir.kt | 32 +++++++++ .../statements/assignments/p-1/neg/2.1.fir.kt | 69 +++++++++++++++++++ .../statements/assignments/p-2/neg/1.1.fir.kt | 41 +++++++++++ .../statements/assignments/p-2/neg/1.2.fir.kt | 59 ++++++++++++++++ .../p-3/neg/1.1.fir.kt | 33 +++++++++ .../while-loop-statement/p-3/neg/1.1.fir.kt | 29 ++++++++ 6 files changed, 263 insertions(+) create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/assignments/operator-assignments/p-2/neg/1.1.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.1.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.2.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/do-while-loop-statement/p-3/neg/1.1.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/while-loop-statement/p-3/neg/1.1.fir.kt diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/operator-assignments/p-2/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/operator-assignments/p-2/neg/1.1.fir.kt new file mode 100644 index 00000000000..85aeccb3069 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/operator-assignments/p-2/neg/1.1.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-253 + * PLACE: statements, assignments, operator-assignments -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: statements, assignments, operator-assignments -> paragraph 2 -> sentence 2 + * statements, assignments, operator-assignments -> paragraph 2 -> sentence 3 + * statements, assignments, operator-assignments -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: An operator assignment A+=B + */ + + +class B(var a: Int) { + operator fun plus(value: Int): B { + a= a + value + return this + } + operator fun plusAssign(value: Int): Unit { + a= a + value + } +} + +// TESTCASE NUMBER: 1 +fun case1() { + var b = B(1) + b += 1 +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt new file mode 100644 index 00000000000..0dad1d40481 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt @@ -0,0 +1,69 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-222 + * PLACE: statements, assignments -> paragraph 1 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Both left-hand and right-hand sides of an assignment must be expressions + */ + + +/* + * TESTCASE NUMBER: 1 + * NOTE: right-hand side of an assignment must be expression + */ +fun case1() { + val x = for () { } + val y = for (x in 1..2) { } + + val a = while () { } + val b = while (false) { } + val c = while () ; +} + +/* + * TESTCASE NUMBER: 2 + * NOTE: right-hand side of an assignment must be expression + */ +fun case2() { + var x = for () { } + var y = for (x in 1..2) { } + + var a = while () { } + var b = while (false) { } + var c = while () ; +} + +/* + * TESTCASE NUMBER: 3 + * NOTE: right-hand side of an assignment must be expression + */ +fun case3() { + var x :Any? + var y :Any? + + var a :Any? + var b :Any? + var c :Any? + + x = for () { } + y = for (x in 1..2) { } + + a = while () { } + b = while (false) { } + c = while () ; +} + +/* + * TESTCASE NUMBER: 4 + * NOTE: left-hand side of an assignment must be expression + */ +fun case4() { + for (x in 1..2) {} = TODO(); + + while (false) { } = TODO() +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.1.fir.kt new file mode 100644 index 00000000000..9c66025d72f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.1.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-222 + * PLACE: statements, assignments -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: statements, assignments -> paragraph 3 -> sentence 1 + * statements, assignments, simple-assignments -> paragraph 1 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Check the expression is not assignable if an identifier referring to an unmutable property + */ + +/* + * TESTCASE NUMBER: 1 + * NOTE: an identifier referring to a unmutable property + */ +fun case1() { + val x : Any + x = "0" + x = 1 + x = 2.0 + + val y : Any = 0 + y = "0" + y = 1.0 +} + +/* + * TESTCASE NUMBER: 2 + * NOTE: an identifier referring to a unmutable property + */ +fun case2() { + val x : Any + mutableListOf(0).forEach({ x = it }) + + val y : Any = 1 + mutableListOf(1).forEach({ y = it }) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.2.fir.kt new file mode 100644 index 00000000000..2a34f7e3e1b --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-2/neg/1.2.fir.kt @@ -0,0 +1,59 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNSAFE_CALL -UNREACHABLE_CODE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-222 + * PLACE: statements, assignments -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: statements, assignments -> paragraph 3 -> sentence 2 + * statements, assignments, simple-assignments -> paragraph 1 -> sentence 2 + * NUMBER: 2 + * DESCRIPTION: Check the expression is not assignable if a navigation expression referring to an unmutable property + */ + + +/* + * TESTCASE NUMBER: 1 + * NOTE: a navigation expression referring to a unmutable property + */ +fun case1() { + val x : Case1? = Case1() + x.x = "0" + x?.x = "0" + x::x = TODO() +} + +class Case1{ + val x : Any? + get() { TODO() } +} + +/* + * TESTCASE NUMBER: 2 + * NOTE: an identifier referring to a ununmutable property + */ +fun case2() { + val x : Case2? = Case2(null) + x.x = "0" + x?.x = "0" + x::x = TODO() +} + +class Case2(val x: Any?) {} + +/* + * TESTCASE NUMBER: 3 + * NOTE: an identifier referring to a ununmutable property + */ +fun case3() { + val x : Case3? = Case3() + x.x = "0" + x?.x = "0" + x::x = TODO() +} + +class Case3() { + val x: Any? = null +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/do-while-loop-statement/p-3/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/do-while-loop-statement/p-3/neg/1.1.fir.kt new file mode 100644 index 00000000000..7f1f5cc840f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/do-while-loop-statement/p-3/neg/1.1.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-253 + * PLACE: statements, loop-statements, do-while-loop-statement -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: statements, loop-statements, do-while-loop-statement -> paragraph 1 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: condition expression is not a subtype of kotlin.Boolean. + */ + +// TESTCASE NUMBER: 1 +fun case1() { + do { + } while ("boo") +} + +// TESTCASE NUMBER: 2 +fun case2() { + val condition: Any = true + do { + } while (condition) +} + +// TESTCASE NUMBER: 3 +fun case3() { + val condition: Boolean? = true + do { + } while (condition) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/while-loop-statement/p-3/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/while-loop-statement/p-3/neg/1.1.fir.kt new file mode 100644 index 00000000000..1699ace6181 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/loop-statements/while-loop-statement/p-3/neg/1.1.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-253 + * PLACE: statements, loop-statements, while-loop-statement -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: statements, loop-statements, while-loop-statement -> paragraph 1 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: condition expression is not a subtype of kotlin.Boolean. + * HELPERS: checkType + */ + +// FILE: KotlinClass.kt +// TESTCASE NUMBER: 1 +fun case1() { + val condition: Any = true + while (condition && "true") { + } +} + +// TESTCASE NUMBER: 2 +fun case2() { + val condition: Boolean? = true + while (condition) { + } +}