diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt new file mode 100644 index 00000000000..e68120a59cf --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt @@ -0,0 +1,39 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2 + * RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false. + */ + +fun box(): String { + + val aval = A() + val x = aval.a(true) && + aval.b(true) && + aval.c(false) && + aval.d(false) + + if (aval.a && aval.b && aval.c && !aval.d && !x) + return "OK" + return "NOK" +} + + +class A (var a: Boolean = false, + var b: Boolean = false, + var c: Boolean = false, + var d: Boolean = false){ + + fun a(a: Boolean): Boolean { this.a = true; return a } + + fun b(a: Boolean): Boolean { this.b = true; return a } + + fun c(a: Boolean): Boolean { this.c = true; return a } + + fun d(a: Boolean): Boolean { this.d = true; return a } +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt new file mode 100644 index 00000000000..55ab7131bc7 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt @@ -0,0 +1,25 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2 + * RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1 + * NUMBER: 2 + * DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false. + */ + +fun box(): String { + val x: Boolean + try { + x = true && true && false && throw MyException() + } catch (e: MyException) { + return "NOK" + } + if (x) + return "NOK" + return "OK" +} + +class MyException : Exception() {} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt new file mode 100644 index 00000000000..dd956da5936 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt @@ -0,0 +1,24 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2 + * RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1 + * NUMBER: 3 + * DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false. + */ + +fun box(): String { + val x: Boolean = false + try { + x = (throw MyException()) && true + } catch (e: MyException) { + if (!x) + return "OK" + } + return "NOK" +} + +class MyException : Exception() {} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/testsMap.json new file mode 100644 index 00000000000..e318ab33f7a --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/testsMap.json @@ -0,0 +1,49 @@ +{ + "1": { + "pos": { + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "unexpectedBehaviour": false + } + ], + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg/1.1.kt new file mode 100644 index 00000000000..5beab237124 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-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-conjunction-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 2 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Both operands of a logical conjunction 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 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-conjunction-expression/p-2/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/pos/1.1.kt new file mode 100644 index 00000000000..48e733368d8 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-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-conjunction-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 2 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Both operands of a logical conjunction 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-conjunction-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/testsMap.json new file mode 100644 index 00000000000..bef74118c5d --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/testsMap.json @@ -0,0 +1,42 @@ +{ + "2": { + "neg": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 7, + "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": 7, + "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-conjunction-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-conjunction-expression/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ 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 index 87f72bccb2e..667c859eab7 100644 --- 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 @@ -4,16 +4,16 @@ "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.", + "casesNumber": 7, + "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.", "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.", + "casesNumber": 7, + "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.", "path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt", "unexpectedBehaviour": false } @@ -24,7 +24,7 @@ { "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", + "description": "Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean", "unexpectedBehaviour": false } ], @@ -32,7 +32,7 @@ { "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", + "description": "Both operands of a logical disjunction 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 } 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 2c2f5d0e38b..00b09cd25d6 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 @@ -1604,6 +1604,68 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Logical_conjunction_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInLogical_conjunction_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-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-conjunction-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-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-conjunction-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-conjunction-expression/p-2/neg"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-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-conjunction-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-conjunction-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java index 181ba6a2dd1..b0e0c6e7679 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java @@ -1051,6 +1051,60 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Logical_conjunction_expression extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInLogical_conjunction_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_1 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_1() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("2.1.kt") + public void test2_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt"); + } + + @TestMetadata("2.2.kt") + public void test2_2() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt"); + } + + @TestMetadata("2.3.kt") + public void test2_3() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-disjunction-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)