diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt new file mode 100644 index 00000000000..5a27f78cbca --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt @@ -0,0 +1,81 @@ +// !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-218 + * PLACE: expressions, logical-disjunction-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, logical-disjunction-expression -> paragraph 2 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error. + * HELPERS: checkType + */ + +// MODULE: libModule +// FILE: libModule/JavaClass.java +package libModule; + +public class JavaClass { + public static Object VALUE = false; +} + +// MODULE: mainModule(libModule) +// FILE: KotlinClass.kt +package mainModule +import libModule.* +import checkSubtype +import checkType +import check + +// TESTCASE NUMBER: 0 +fun foo() = run { false || JavaClass.VALUE || throw Exception() } + +// TESTCASE NUMBER: 1 +fun case1() { + val a: Boolean? = false + checkSubtype(a) + val x4 = a || true + x4 checkType { check() } +} + +// TESTCASE NUMBER: 2 +fun case2() { + val a: Any = false + a + val x4 = a || true + x4 checkType { check() } +} + +// TESTCASE NUMBER: 3 +fun case3() { + val a1 = false + val a2 = JavaClass.VALUE + a2 + + val x3 = a1 || a2 + x3 + + x3 checkType { check() } +} + +// TESTCASE NUMBER: 4 +fun case4() { + var x = false || ; +} + +// TESTCASE NUMBER: 5 +fun case5() { + var y = false || +} + +// TESTCASE NUMBER: 5 +fun case5() { + var x = || +} + +// TESTCASE NUMBER: 6 +fun case6() { + var x = || false || true +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt new file mode 100644 index 00000000000..335d004a121 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, logical-disjunction-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, logical-disjunction-expression -> paragraph 2 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION:Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean + * HELPERS: checkType + */ + +// MODULE: libModule +// FILE: libModule/JavaClass.java +package libModule; + +public class JavaClass { + public static boolean VALUE; + + public static Object VALUE_OBJ = true; + + public Boolean getValue () + { return new Boolean ("true"); } +} + +// MODULE: mainModule(libModule) +// FILE: KotlinClass.kt +package mainModule +import libModule.* +import checkSubtype +import checkType +import check + +fun foo() = run { false || JavaClass.VALUE || throw Exception() } + + +// TESTCASE NUMBER: 1 +fun case1() { + val a1 = false + val a2 = JavaClass.VALUE + val a3 = foo() + val a4 = JavaClass().getValue() + val a5 = JavaClass.VALUE_OBJ + + checkSubtype(a1) + checkSubtype(a2) + checkSubtype(a3) + checkSubtype(a4) + + val x3 = a1 || a2 || a3 || a4 || a5 as Boolean + x3 + + x3 checkType { check()} +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/testsMap.json new file mode 100644 index 00000000000..87f72bccb2e --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/testsMap.json @@ -0,0 +1,42 @@ +{ + "2": { + "neg": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 6, + "description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.", + "unexpectedBehaviour": false + } + ], + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 6, + "description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.", + "path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt", + "unexpectedBehaviour": false + } + ] + }, + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 1, + "description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean", + "unexpectedBehaviour": false + } + ], + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 1, + "description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean", + "path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index b78f3f9c548..2c2f5d0e38b 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java @@ -25,7 +25,7 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } public void testAllFilesPresentInDiagnostics() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "linked/type-inference", "linked/expressions.when-expression", "linked/type-system/type-kinds/type-parameters", "linked/type-system/subtyping", "linked/control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "linked/declarations/classifier-declaration/classifier-initialization", "linked/declarations/function-declaration", "linked/declarations/property-declaration/property-initialization", "linked/annotations", "linked/statements", "linked/inheritance", "linked/expressions.conditional-expression", "linked/expressions/logical-disjunction-expression", "linked/expressions/function-literals", "linked/expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "linked/overload-resolution", "linked/control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "linked/type-inference", "linked/expressions.when-expression", "linked/type-system/type-kinds/type-parameters", "linked/type-system/subtyping", "linked/control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "linked/declarations/classifier-declaration/classifier-initialization", "linked/declarations/function-declaration", "linked/declarations/property-declaration/property-initialization", "linked/annotations", "linked/statements", "linked/inheritance", "linked/expressions.conditional-expression", "linked/expressions/function-literals", "linked/expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "linked/overload-resolution", "linked/control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked") @@ -37,7 +37,7 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } public void testAllFilesPresentInLinked() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked"), Pattern.compile("^(.+)\\.kt$"), true, "type-inference", "expressions.when-expression", "type-system/type-kinds/type-parameters", "type-system/subtyping", "control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "declarations/classifier-declaration/classifier-initialization", "declarations/function-declaration", "declarations/property-declaration/property-initialization", "annotations", "statements", "inheritance", "expressions.conditional-expression", "expressions/logical-disjunction-expression", "expressions/function-literals", "expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "overload-resolution", "control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked"), Pattern.compile("^(.+)\\.kt$"), true, "type-inference", "expressions.when-expression", "type-system/type-kinds/type-parameters", "type-system/subtyping", "control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "declarations/classifier-declaration/classifier-initialization", "declarations/function-declaration", "declarations/property-declaration/property-initialization", "annotations", "statements", "inheritance", "expressions.conditional-expression", "expressions/function-literals", "expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "overload-resolution", "control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis") @@ -452,7 +452,7 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } public void testAllFilesPresentInExpressions() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), true, "logical-disjunction-expression", "function-literals", "built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), true, "function-literals", "built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg"); } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/built-in-types-and-their-semantics") @@ -1604,6 +1604,68 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Logical_disjunction_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInLogical_disjunction_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_2 extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_2() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Neg extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt"); + } + + public void testAllFilesPresentInNeg() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)