diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 332af36c5cd..325b272b706 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -4726,6 +4726,226 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator") + @TestDataPath("$PROJECT_ROOT") + public class ConstantEvaluator { + @Test + public void testAllFilesPresentInConstantEvaluator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/constant") + @TestDataPath("$PROJECT_ROOT") + public class Constant { + @Test + public void testAllFilesPresentInConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/constant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("classObjectProperty.kt") + public void testClassObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt"); + } + + @Test + @TestMetadata("compareTo.kt") + public void testCompareTo() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt"); + } + + @Test + @TestMetadata("differentTypes.kt") + public void testDifferentTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt"); + } + + @Test + @TestMetadata("divideByZero.kt") + public void testDivideByZero() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt"); + } + + @Test + @TestMetadata("equals.kt") + public void testEquals() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt"); + } + + @Test + @TestMetadata("exceptionWhenEvaluate.kt") + public void testExceptionWhenEvaluate() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt"); + } + + @Test + @TestMetadata("finalProperty.kt") + public void testFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt"); + } + + @Test + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt"); + } + + @Test + @TestMetadata("floatsAndDoubles.kt") + public void testFloatsAndDoubles() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt"); + } + + @Test + @TestMetadata("integer.kt") + public void testInteger() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt"); + } + + @Test + @TestMetadata("integerOperations.kt") + public void testIntegerOperations() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt"); + } + + @Test + @TestMetadata("integers.kt") + public void testIntegers() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt"); + } + + @Test + @TestMetadata("localVal.kt") + public void testLocalVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt"); + } + + @Test + @TestMetadata("localVar.kt") + public void testLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt"); + } + + @Test + @TestMetadata("nonFinalProperty.kt") + public void testNonFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt"); + } + + @Test + @TestMetadata("objectProperty.kt") + public void testObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt"); + } + + @Test + @TestMetadata("strings.kt") + public void testStrings() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt"); + } + + @Test + @TestMetadata("topLevelVal.kt") + public void testTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt"); + } + + @Test + @TestMetadata("topLevelVar.kt") + public void testTopLevelVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/isPure") + @TestDataPath("$PROJECT_ROOT") + public class IsPure { + @Test + public void testAllFilesPresentInIsPure() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/isPure"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("innerToType.kt") + public void testInnerToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt"); + } + + @Test + @TestMetadata("namedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt"); + } + + @Test + @TestMetadata("toType.kt") + public void testToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant") + @TestDataPath("$PROJECT_ROOT") + public class UsesVariableAsConstant { + @Test + public void testAllFilesPresentInUsesVariableAsConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("binaryTypes.kt") + public void testBinaryTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt"); + } + + @Test + @TestMetadata("NamedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt"); + } + + @Test + @TestMetadata("OtherTypes.kt") + public void testOtherTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt"); + } + + @Test + @TestMetadata("simpleTypes.kt") + public void testSimpleTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 398417459b3..451b8021b9f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -4726,6 +4726,226 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator") + @TestDataPath("$PROJECT_ROOT") + public class ConstantEvaluator { + @Test + public void testAllFilesPresentInConstantEvaluator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/constant") + @TestDataPath("$PROJECT_ROOT") + public class Constant { + @Test + public void testAllFilesPresentInConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/constant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("classObjectProperty.kt") + public void testClassObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt"); + } + + @Test + @TestMetadata("compareTo.kt") + public void testCompareTo() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt"); + } + + @Test + @TestMetadata("differentTypes.kt") + public void testDifferentTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt"); + } + + @Test + @TestMetadata("divideByZero.kt") + public void testDivideByZero() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt"); + } + + @Test + @TestMetadata("equals.kt") + public void testEquals() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt"); + } + + @Test + @TestMetadata("exceptionWhenEvaluate.kt") + public void testExceptionWhenEvaluate() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt"); + } + + @Test + @TestMetadata("finalProperty.kt") + public void testFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt"); + } + + @Test + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt"); + } + + @Test + @TestMetadata("floatsAndDoubles.kt") + public void testFloatsAndDoubles() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt"); + } + + @Test + @TestMetadata("integer.kt") + public void testInteger() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt"); + } + + @Test + @TestMetadata("integerOperations.kt") + public void testIntegerOperations() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt"); + } + + @Test + @TestMetadata("integers.kt") + public void testIntegers() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt"); + } + + @Test + @TestMetadata("localVal.kt") + public void testLocalVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt"); + } + + @Test + @TestMetadata("localVar.kt") + public void testLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt"); + } + + @Test + @TestMetadata("nonFinalProperty.kt") + public void testNonFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt"); + } + + @Test + @TestMetadata("objectProperty.kt") + public void testObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt"); + } + + @Test + @TestMetadata("strings.kt") + public void testStrings() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt"); + } + + @Test + @TestMetadata("topLevelVal.kt") + public void testTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt"); + } + + @Test + @TestMetadata("topLevelVar.kt") + public void testTopLevelVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/isPure") + @TestDataPath("$PROJECT_ROOT") + public class IsPure { + @Test + public void testAllFilesPresentInIsPure() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/isPure"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("innerToType.kt") + public void testInnerToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt"); + } + + @Test + @TestMetadata("namedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt"); + } + + @Test + @TestMetadata("toType.kt") + public void testToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant") + @TestDataPath("$PROJECT_ROOT") + public class UsesVariableAsConstant { + @Test + public void testAllFilesPresentInUsesVariableAsConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("binaryTypes.kt") + public void testBinaryTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt"); + } + + @Test + @TestMetadata("NamedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt"); + } + + @Test + @TestMetadata("OtherTypes.kt") + public void testOtherTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt"); + } + + @Test + @TestMetadata("simpleTypes.kt") + public void testSimpleTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt index 600c2f5bb47..db5098741f4 100644 --- a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt +++ b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt @@ -87,6 +87,10 @@ class TreesCompareTest : AbstractRawFirBuilderTestCase() { if (file.name.endsWith(".fir.kt")) { return@compareBase true } + if (file.path.replace("\\", "/") == "compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt") { + // `DIAGNOSTIC_IN_TESTDATA_PATTERN` fails to correctly strip diagnostics from this file + return@compareBase true + } val notEditedText = FileUtil.loadFile(file, CharsetToolkit.UTF8, true).trim() val text = notEditedText.replace(DIAGNOSTIC_IN_TESTDATA_PATTERN, "").replaceAfter(".java", "") diff --git a/compiler/testData/evaluate/constant/classObjectProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.fir.kt similarity index 92% rename from compiler/testData/evaluate/constant/classObjectProperty.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.fir.kt index 113a1f243d5..0b03202dda7 100644 --- a/compiler/testData/evaluate/constant/classObjectProperty.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.fir.kt @@ -14,7 +14,7 @@ class A { val prop4 = A.a + 1 // val prop7: 0 - open val prop7 = 0 + open val prop7 = 0 // val prop8: null val prop8 = prop7 @@ -52,4 +52,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt new file mode 100644 index 00000000000..30503215f4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt @@ -0,0 +1,55 @@ +package test + +// val prop1: 1 +val prop1 = A.a + +// val prop2: 2 +val prop2 = A.a + 1 + +class A { + // val prop3: 1 + val prop3 = A.a + + // val prop4: 2 + val prop4 = A.a + 1 + + // val prop7: 0 + open val prop7 = 0 + + // val prop8: null + val prop8 = prop7 + + companion object { + val a = 1 + } +} + +fun foo() { + // val prop5: 1 + val prop5 = A.a + + // val prop6: 2 + val prop6 = A.a + 1 + + val b = { + // val prop11: 1 + val prop11 = A.a + + // val prop12: 2 + val prop12 = A.a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: 1 + val prop9 = A.a + + // val prop10: 2 + val prop10 = A.a + 1 + } + } +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.txt new file mode 100644 index 00000000000..a13ec377519 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.txt @@ -0,0 +1,33 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.Int = 2 + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public final val prop3: kotlin.Int = 1 + public final val prop4: kotlin.Int = 2 + public open val prop7: kotlin.Int = 0 + public final val prop8: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public companion object Companion { + private constructor Companion() + public final val a: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/compareTo.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.fir.kt similarity index 100% rename from compiler/testData/evaluate/constant/compareTo.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt new file mode 100644 index 00000000000..73ddcb26023 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt @@ -0,0 +1,19 @@ +package test + +// val prop1: false +val prop1 = 1 > 2 + +// val prop2: true +val prop2 = 1 < 2 + +// val prop3: true +val prop3 = 1 <= 2 + +// val prop4: false +val prop4 = 1 >= 2 + +// val prop5: -1 +val prop5 = 1.compareTo(2) + +// val prop6: false +val prop6 = 1.compareTo(2) > 0 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.txt new file mode 100644 index 00000000000..fd0364b104c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.txt @@ -0,0 +1,10 @@ +package + +package test { + public val prop1: kotlin.Boolean = false + public val prop2: kotlin.Boolean = true + public val prop3: kotlin.Boolean = true + public val prop4: kotlin.Boolean = false + public val prop5: kotlin.Int = -1 + public val prop6: kotlin.Boolean = false +} diff --git a/compiler/testData/evaluate/constant/differentTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.fir.kt similarity index 72% rename from compiler/testData/evaluate/constant/differentTypes.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.fir.kt index 177b6806ec8..5eabbf8dbfa 100644 --- a/compiler/testData/evaluate/constant/differentTypes.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.fir.kt @@ -31,15 +31,15 @@ val prop9: Any? = "a" val prop10: Any = "a" // val prop11: null -val prop11: aaa = 1 +val prop11: aaa = 1 // val prop14: null -val prop14: aaa? = 1 +val prop14: aaa? = 1 class A // val prop15: null -val prop15: A = 1 +val prop15: A = 1 // val prop16: 1 -val prop16: A? = 1 +val prop16: A? = 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt new file mode 100644 index 00000000000..44691429b51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt @@ -0,0 +1,45 @@ +package test + +// val prop1: 1 +val prop1: Int = 1 + +// val prop2: 1 +val prop2: Int? = 1 + +// val prop3: 1 +val prop3: Number? = 1 + +// val prop4: 1 +val prop4: Any? = 1 + +// val prop5: 1 +val prop5: Number = 1 + +// val prop6: 1 +val prop6: Any = 1 + +// val prop7: \"a\" +val prop7: String = "a" + +// val prop8: \"a\" +val prop8: String? = "a" + +// val prop9: \"a\" +val prop9: Any? = "a" + +// val prop10: \"a\" +val prop10: Any = "a" + +// val prop11: null +val prop11: aaa = 1 + +// val prop14: null +val prop14: aaa? = 1 + +class A + +// val prop15: null +val prop15: A = 1 + +// val prop16: 1 +val prop16: A? = 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.txt new file mode 100644 index 00000000000..3865860b780 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.txt @@ -0,0 +1,25 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop10: kotlin.Any = "a" + public val prop11: [ERROR : aaa] + public val prop14: [ERROR : aaa]? + public val prop15: test.A + public val prop16: test.A? = 1 + public val prop2: kotlin.Int? = 1 + public val prop3: kotlin.Number? = 1 + public val prop4: kotlin.Any? = 1 + public val prop5: kotlin.Number = 1 + public val prop6: kotlin.Any = 1 + public val prop7: kotlin.String = "a" + public val prop8: kotlin.String? = "a" + public val prop9: kotlin.Any? = "a" + + public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/divideByZero.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.fir.kt similarity index 67% rename from compiler/testData/evaluate/constant/divideByZero.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.fir.kt index 6872bcd10ad..9a651fcc3f7 100644 --- a/compiler/testData/evaluate/constant/divideByZero.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.fir.kt @@ -1,13 +1,13 @@ package test // val prop1: null -val prop1 = 1 / 0 +val prop1 = 1 / 0 // val prop2: Infinity.toDouble() -val prop2 = 1 / 0.0 +val prop2 = 1 / 0.0 // val prop3: Infinity.toDouble() -val prop3 = 1.0 / 0 +val prop3 = 1.0 / 0 // val prop4: 10.0.toDouble() val prop4 = 1 / 0.1 @@ -34,28 +34,28 @@ val prop10 = 1.0 / 0.toFloat() val prop11 = 1.0 / 0.toDouble() // val prop12: -Infinity.toDouble() -val prop12 = -1.0 / 0 +val prop12 = -1.0 / 0 // val prop13: Infinity.toFloat() -val prop13 = 1f / 0 +val prop13 = 1f / 0 // val prop14: -Infinity.toFloat() -val prop14 = -1f / 0 +val prop14 = -1f / 0 // val prop15: NaN.toDouble() -val prop15 = 0.0 / 0 +val prop15 = 0.0 / 0 // val prop16: NaN.toFloat() -val prop16 = 0f / 0 +val prop16 = 0f / 0 // val prop17: NaN.toDouble() -val prop17 = -0.0 / 0 +val prop17 = -0.0 / 0 // val prop18: NaN.toDouble() -val prop18 = 1.0 / 0 - 1.0 / 0 +val prop18 = 1.0 / 0 - 1.0 / 0 // val prop19: NaN.toFloat() -val prop19 = 1f / 0 - 1f / 0 +val prop19 = 1f / 0 - 1f / 0 // val prop20: NaN.toDouble() val prop20 = 1.0 % 0 @@ -76,4 +76,4 @@ val prop24 = -0.0 % 0 val prop26 = 1.0.rem(0) // val prop27: Infinity.toDouble() -val prop27 = 1.0.div(0) \ No newline at end of file +val prop27 = 1.0.div(0) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt new file mode 100644 index 00000000000..b4334934308 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt @@ -0,0 +1,79 @@ +package test + +// val prop1: null +val prop1 = 1 / 0 + +// val prop2: Infinity.toDouble() +val prop2 = 1 / 0.0 + +// val prop3: Infinity.toDouble() +val prop3 = 1.0 / 0 + +// val prop4: 10.0.toDouble() +val prop4 = 1 / 0.1 + +// val prop5: null +val prop5 = 1 / 0.toLong() + +// val prop6: Infinity.toDouble() +val prop6 = 1.0 / 0.toInt() + +// val prop7: Infinity.toDouble() +val prop7 = 1.0 / 0.toLong() + +// val prop8: Infinity.toDouble() +val prop8 = 1.0 / 0.toByte() + +// val prop9: Infinity.toDouble() +val prop9 = 1.0 / 0.toShort() + +// val prop10: Infinity.toDouble() +val prop10 = 1.0 / 0.toFloat() + +// val prop11: Infinity.toDouble() +val prop11 = 1.0 / 0.toDouble() + +// val prop12: -Infinity.toDouble() +val prop12 = -1.0 / 0 + +// val prop13: Infinity.toFloat() +val prop13 = 1f / 0 + +// val prop14: -Infinity.toFloat() +val prop14 = -1f / 0 + +// val prop15: NaN.toDouble() +val prop15 = 0.0 / 0 + +// val prop16: NaN.toFloat() +val prop16 = 0f / 0 + +// val prop17: NaN.toDouble() +val prop17 = -0.0 / 0 + +// val prop18: NaN.toDouble() +val prop18 = 1.0 / 0 - 1.0 / 0 + +// val prop19: NaN.toFloat() +val prop19 = 1f / 0 - 1f / 0 + +// val prop20: NaN.toDouble() +val prop20 = 1.0 % 0 + +// val prop21: NaN.toDouble() +val prop21 = 0.0 % 0 + +// val prop22: NaN.toFloat() +val prop22 = 1f % 0 + +// val prop23: NaN.toDouble() +val prop23 = -1.0 % 0 + +// val prop24: NaN.toDouble() +val prop24 = -0.0 % 0 + +// val prop26: NaN.toDouble() +val prop26 = 1.0.rem(0) + +// val prop27: Infinity.toDouble() +val prop27 = 1.0.div(0) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.txt new file mode 100644 index 00000000000..f734c97488e --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.txt @@ -0,0 +1,30 @@ +package + +package test { + public val prop1: kotlin.Int + public val prop10: kotlin.Double = Infinity.toDouble() + public val prop11: kotlin.Double = Infinity.toDouble() + public val prop12: kotlin.Double = -Infinity.toDouble() + public val prop13: kotlin.Float = Infinity.toFloat() + public val prop14: kotlin.Float = -Infinity.toFloat() + public val prop15: kotlin.Double = NaN.toDouble() + public val prop16: kotlin.Float = NaN.toFloat() + public val prop17: kotlin.Double = NaN.toDouble() + public val prop18: kotlin.Double = NaN.toDouble() + public val prop19: kotlin.Float = NaN.toFloat() + public val prop2: kotlin.Double = Infinity.toDouble() + public val prop20: kotlin.Double = NaN.toDouble() + public val prop21: kotlin.Double = NaN.toDouble() + public val prop22: kotlin.Float = NaN.toFloat() + public val prop23: kotlin.Double = NaN.toDouble() + public val prop24: kotlin.Double = NaN.toDouble() + public val prop26: kotlin.Double = NaN.toDouble() + public val prop27: kotlin.Double = Infinity.toDouble() + public val prop3: kotlin.Double = Infinity.toDouble() + public val prop4: kotlin.Double = 10.0.toDouble() + public val prop5: kotlin.Long + public val prop6: kotlin.Double = Infinity.toDouble() + public val prop7: kotlin.Double = Infinity.toDouble() + public val prop8: kotlin.Double = Infinity.toDouble() + public val prop9: kotlin.Double = Infinity.toDouble() +} diff --git a/compiler/testData/evaluate/constant/equals.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.fir.kt similarity index 100% rename from compiler/testData/evaluate/constant/equals.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt new file mode 100644 index 00000000000..5e50bbeb515 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt @@ -0,0 +1,4 @@ +package test + +// val prop4: true +val prop4 = !1.equals(2) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.txt new file mode 100644 index 00000000000..99a91f7a651 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.txt @@ -0,0 +1,5 @@ +package + +package test { + public val prop4: kotlin.Boolean = true +} diff --git a/compiler/testData/evaluate/constant/exceptionWhenEvaluate.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.fir.kt similarity index 60% rename from compiler/testData/evaluate/constant/exceptionWhenEvaluate.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.fir.kt index 452abff742e..138bdc53db8 100644 --- a/compiler/testData/evaluate/constant/exceptionWhenEvaluate.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.fir.kt @@ -1,4 +1,4 @@ package test // val prop1: null -val prop1 = "".get(0) \ No newline at end of file +val prop1 = "".get(0) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt new file mode 100644 index 00000000000..a4f57e078f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt @@ -0,0 +1,4 @@ +package test + +// val prop1: null +val prop1 = "".get(0) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.txt new file mode 100644 index 00000000000..a18de4f64e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.txt @@ -0,0 +1,5 @@ +package + +package test { + public val prop1: kotlin.Char +} diff --git a/compiler/testData/evaluate/constant/finalProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/finalProperty.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.fir.kt index fb1c28c70f3..80a5015b455 100644 --- a/compiler/testData/evaluate/constant/finalProperty.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.fir.kt @@ -52,4 +52,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt new file mode 100644 index 00000000000..0de374878c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt @@ -0,0 +1,55 @@ +package test + +// val prop1: 1 +val prop1 = A().a + +// val prop2: 2 +val prop2 = A().a + 1 + +class A() { + val a = 1 + + // val prop3: 1 + val prop3 = a + + // val prop4: 2 + val prop4 = a + 1 + + fun foo() { + // val prop5: 1 + val prop5 = A().a + + // val prop6: 2 + val prop6 = A().a + 1 + + val b = { + // val prop11: 1 + val prop11 = A().a + + // val prop12: 2 + val prop12 = A().a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: 1 + val prop9 = A().a + + // val prop10: 2 + val prop10 = A().a + 1 + } + } + } +} + +fun foo() { + // val prop7: 1 + val prop7 = A().a + + // val prop8: 2 + val prop8 = A().a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.txt new file mode 100644 index 00000000000..f898fe5152b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.txt @@ -0,0 +1,25 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.Int = 2 + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public final val a: kotlin.Int = 1 + public final val prop3: kotlin.Int = 1 + public final val prop4: kotlin.Int = 2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/float.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.fir.kt similarity index 100% rename from compiler/testData/evaluate/constant/float.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/float.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt new file mode 100644 index 00000000000..f5113642e63 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt @@ -0,0 +1,25 @@ +package test + +// val prop1: 1.0.toFloat() +val prop1 = 1F + +// val prop2: 1.0.toFloat() +val prop2 = 1.0F + +// val prop3: 0.1.toFloat() +val prop3 = 1e-1F + +// val prop4: 0.1.toFloat() +val prop4 = 1.0e-1F + +// val prop5: 1.0.toFloat() +val prop5 = 1f + +// val prop6: 1.0.toFloat() +val prop6 = 1.0f + +// val prop7: 0.1.toFloat() +val prop7 = 1e-1f + +// val prop8: 0.1.toFloat() +val prop8 = 1.0e-1f diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.txt new file mode 100644 index 00000000000..b0db31d2447 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/float.txt @@ -0,0 +1,12 @@ +package + +package test { + public val prop1: kotlin.Float = 1.0.toFloat() + public val prop2: kotlin.Float = 1.0.toFloat() + public val prop3: kotlin.Float = 0.1.toFloat() + public val prop4: kotlin.Float = 0.1.toFloat() + public val prop5: kotlin.Float = 1.0.toFloat() + public val prop6: kotlin.Float = 1.0.toFloat() + public val prop7: kotlin.Float = 0.1.toFloat() + public val prop8: kotlin.Float = 0.1.toFloat() +} diff --git a/compiler/testData/evaluate/constant/floatsAndDoubles.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.fir.kt similarity index 87% rename from compiler/testData/evaluate/constant/floatsAndDoubles.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.fir.kt index 8be0759460c..e6fd8cdeada 100644 --- a/compiler/testData/evaluate/constant/floatsAndDoubles.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.fir.kt @@ -13,7 +13,7 @@ val prop3 = java.lang.Float.MAX_VALUE + 1 val prop4 = java.lang.Float.MAX_VALUE - 1 // val prop5: 3.4028235E38.toFloat() -val prop5: Int = java.lang.Float.MAX_VALUE + 1 +val prop5: Int = java.lang.Float.MAX_VALUE + 1 // val prop6: 2.0.toFloat() val prop6: Float = 1.0.toFloat() + 1 @@ -22,7 +22,7 @@ val prop6: Float = 1.0.toFloat() + 1 val prop7: Double = 1.0 + 1.0 // val prop8: 2.0.toDouble() -val prop8: Float = 1.0.toDouble() + 1.0 +val prop8: Float = 1.0.toDouble() + 1.0 // val prop9: -2.0.toDouble() val prop9: Double = -2.0 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt new file mode 100644 index 00000000000..f2b2a52ffaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt @@ -0,0 +1,49 @@ +package test + +// val prop1: 3.4028235E38.toFloat() +val prop1: Float = java.lang.Float.MAX_VALUE + 1 + +// val prop2: 3.4028234663852886E38.toDouble() +val prop2: Double = java.lang.Float.MAX_VALUE + 1.0 + +// val prop3: 3.4028235E38.toFloat() +val prop3 = java.lang.Float.MAX_VALUE + 1 + +// val prop4: 3.4028235E38.toFloat() +val prop4 = java.lang.Float.MAX_VALUE - 1 + +// val prop5: 3.4028235E38.toFloat() +val prop5: Int = java.lang.Float.MAX_VALUE + 1 + +// val prop6: 2.0.toFloat() +val prop6: Float = 1.0.toFloat() + 1 + +// val prop7: 2.0.toDouble() +val prop7: Double = 1.0 + 1.0 + +// val prop8: 2.0.toDouble() +val prop8: Float = 1.0.toDouble() + 1.0 + +// val prop9: -2.0.toDouble() +val prop9: Double = -2.0 + +// val prop10: Infinity.toFloat() +val prop10: Float = 1.2E400F + +// val prop11: 0.0.toFloat() +val prop11: Float = 1.2E-400F + +// val prop12: Infinity.toFloat() +val prop12: Float = 11111111111111111111111111111111111111111111111111111111111111111F + +// val prop13: 0.0.toFloat() +val prop13: Float = 0.000000000000000000000000000000000000000000000000000000000000001F + +// val prop14: 1.0E-39.toFloat() +val prop14: Float = 0.000000000000000000000000000000000000001000000000000000000000000F + +// val prop15: Infinity.toDouble() +val prop15: Double = 1.2E400 + +// val prop16: 0.0.toDouble() +val prop16: Double = 1.2E-400 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.txt new file mode 100644 index 00000000000..ee360cd33f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.txt @@ -0,0 +1,20 @@ +package + +package test { + public val prop1: kotlin.Float = 3.4028235E38.toFloat() + public val prop10: kotlin.Float = Infinity.toFloat() + public val prop11: kotlin.Float = 0.0.toFloat() + public val prop12: kotlin.Float = Infinity.toFloat() + public val prop13: kotlin.Float = 0.0.toFloat() + public val prop14: kotlin.Float = 1.0E-39.toFloat() + public val prop15: kotlin.Double = Infinity.toDouble() + public val prop16: kotlin.Double = 0.0.toDouble() + public val prop2: kotlin.Double = 3.4028234663852886E38.toDouble() + public val prop3: kotlin.Float = 3.4028235E38.toFloat() + public val prop4: kotlin.Float = 3.4028235E38.toFloat() + public val prop5: kotlin.Int = 3.4028235E38.toFloat() + public val prop6: kotlin.Float = 2.0.toFloat() + public val prop7: kotlin.Double = 2.0.toDouble() + public val prop8: kotlin.Float = 2.0.toDouble() + public val prop9: kotlin.Double = -2.0.toDouble() +} diff --git a/compiler/testData/evaluate/constant/integer.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.fir.kt similarity index 63% rename from compiler/testData/evaluate/constant/integer.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.fir.kt index 3e29ef07aca..1b61989559d 100644 --- a/compiler/testData/evaluate/constant/integer.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.fir.kt @@ -16,16 +16,16 @@ val prop4 = 0b1L val prop5 = 0B1L // val prop6: 1.toLong() -val prop6 = 1l +val prop6 = 1l // val prop7: 1.toLong() -val prop7 = 0x1l +val prop7 = 0x1l // val prop8: 1.toLong() -val prop8 = 0X1l +val prop8 = 0X1l // val prop9: 1.toLong() -val prop9 = 0b1l +val prop9 = 0b1l // val prop10: 1.toLong() -val prop10 = 0B1l +val prop10 = 0B1l diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt new file mode 100644 index 00000000000..f4daf3a2d94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt @@ -0,0 +1,31 @@ +package test + +// val prop1: 1.toLong() +val prop1 = 1L + +// val prop2: 1.toLong() +val prop2 = 0x1L + +// val prop3: 1.toLong() +val prop3 = 0X1L + +// val prop4: 1.toLong() +val prop4 = 0b1L + +// val prop5: 1.toLong() +val prop5 = 0B1L + +// val prop6: 1.toLong() +val prop6 = 1l + +// val prop7: 1.toLong() +val prop7 = 0x1l + +// val prop8: 1.toLong() +val prop8 = 0X1l + +// val prop9: 1.toLong() +val prop9 = 0b1l + +// val prop10: 1.toLong() +val prop10 = 0B1l diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.txt new file mode 100644 index 00000000000..37094f5481a --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.txt @@ -0,0 +1,14 @@ +package + +package test { + public val prop1: kotlin.Long = 1.toLong() + public val prop10: kotlin.Long = 1.toLong() + public val prop2: kotlin.Long = 1.toLong() + public val prop3: kotlin.Long = 1.toLong() + public val prop4: kotlin.Long = 1.toLong() + public val prop5: kotlin.Long = 1.toLong() + public val prop6: kotlin.Long = 1.toLong() + public val prop7: kotlin.Long = 1.toLong() + public val prop8: kotlin.Long = 1.toLong() + public val prop9: kotlin.Long = 1.toLong() +} diff --git a/compiler/testData/evaluate/constant/integerOperations.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.fir.kt similarity index 78% rename from compiler/testData/evaluate/constant/integerOperations.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.fir.kt index 90cd53744fe..6ee6056d61e 100644 --- a/compiler/testData/evaluate/constant/integerOperations.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.fir.kt @@ -1,3 +1,4 @@ +// WITH_STDLIB package test // val x1: 3 @@ -17,7 +18,7 @@ val x5 = 0x1234 and 0x5678 // Strange result, see KT-13517 // val x6: null -val x6 = 0x1234 and 0x5678L +val x6 = 0x1234 and 0x5678L // val x7: 4656.toLong() val x7 = 0x1234L and 0x5678 @@ -26,4 +27,4 @@ val x7 = 0x1234L and 0x5678 val x8 = (-123_456_789_321).floorDiv(1_000_000) // val x9: 79 -val x9 = (-123_456_789_321).mod(100) \ No newline at end of file +val x9 = (-123_456_789_321).mod(100) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt new file mode 100644 index 00000000000..f283f43c749 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt @@ -0,0 +1,30 @@ +// WITH_STDLIB +package test + +// val x1: 3 +val x1 = 1 + 2 + +// val x2: 3.toLong() +val x2 = 1 + 2L + +// val x3: 3 +val x3 = 1.toShort() + 2.toByte() + +// val x4: 3 +val x4 = 1.toByte() + 2.toByte() + +// val x5: 4656 +val x5 = 0x1234 and 0x5678 + +// Strange result, see KT-13517 +// val x6: null +val x6 = 0x1234 and 0x5678L + +// val x7: 4656.toLong() +val x7 = 0x1234L and 0x5678 + +// val x8: -123457 +val x8 = (-123_456_789_321).floorDiv(1_000_000) + +// val x9: 79 +val x9 = (-123_456_789_321).mod(100) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.txt new file mode 100644 index 00000000000..089c0c967eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.txt @@ -0,0 +1,13 @@ +package + +package test { + public val x1: kotlin.Int = 3 + public val x2: kotlin.Long = 3.toLong() + public val x3: kotlin.Int = 3 + public val x4: kotlin.Int = 3 + public val x5: kotlin.Int = 4656 + public val x6: kotlin.Int + public val x7: kotlin.Long = 4656.toLong() + public val x8: kotlin.Int = -123457 + public val x9: kotlin.Int = 79 +} diff --git a/compiler/testData/evaluate/constant/integers.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.fir.kt similarity index 57% rename from compiler/testData/evaluate/constant/integers.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.fir.kt index 04c7d36e2e0..1538bbf4e7f 100644 --- a/compiler/testData/evaluate/constant/integers.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.fir.kt @@ -1,7 +1,8 @@ +// WITH_STDLIB package test // val prop1: 513105426295.toLong() -val prop1: Int = 0x7777777777 +val prop1: Int = 0x7777777777 // val prop2: 513105426295.toLong() val prop2: Long = 0x7777777777 @@ -10,4 +11,4 @@ val prop2: Long = 0x7777777777 val prop3 = 0x7777777777 // val prop4: 10 -const val prop4 = '\n'.code \ No newline at end of file +const val prop4 = '\n'.code diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt new file mode 100644 index 00000000000..753b4799af6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt @@ -0,0 +1,14 @@ +// WITH_STDLIB +package test + +// val prop1: 513105426295.toLong() +val prop1: Int = 0x7777777777 + +// val prop2: 513105426295.toLong() +val prop2: Long = 0x7777777777 + +// val prop3: 513105426295.toLong() +val prop3 = 0x7777777777 + +// val prop4: 10 +const val prop4 = '\n'.code diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.txt new file mode 100644 index 00000000000..e8331b43c0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.txt @@ -0,0 +1,8 @@ +package + +package test { + public val prop1: kotlin.Int = 513105426295.toLong() + public val prop2: kotlin.Long = 513105426295.toLong() + public val prop3: kotlin.Long = 513105426295.toLong() + public const val prop4: kotlin.Int = 10 +} diff --git a/compiler/testData/evaluate/constant/localVal.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/localVal.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.fir.kt index 9c5cbf1febf..bb0df541d69 100644 --- a/compiler/testData/evaluate/constant/localVal.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.fir.kt @@ -50,4 +50,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt new file mode 100644 index 00000000000..92bd01f1de2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt @@ -0,0 +1,53 @@ +package test + +class A() { + fun foo() { + val a = 1 + + // val prop5: 1 + val prop5 = a + + // val prop6: 2 + val prop6 = a + 1 + + fun local() { + // val prop1: 1 + val prop1 = a + + // val prop2: 2 + val prop2 = a + 1 + } + + val b = { + // val prop3: 1 + val prop3 = a + + // val prop4: 2 + val prop4 = a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: 1 + val prop9 = a + + // val prop10: 2 + val prop10 = a + 1 + } + } + } +} + +fun foo() { + val a = 1 + + // val prop7: 1 + val prop7 = a + + // val prop8: 2 + val prop8 = a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.txt new file mode 100644 index 00000000000..f0da6ac1414 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.txt @@ -0,0 +1,20 @@ +package + +package test { + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/localVar.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/localVar.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.fir.kt index 5b8a2688f99..a940a09e39b 100644 --- a/compiler/testData/evaluate/constant/localVar.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.fir.kt @@ -50,4 +50,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt new file mode 100644 index 00000000000..f9b4f41a697 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt @@ -0,0 +1,53 @@ +package test + +class A() { + fun foo() { + var a = 1 + + // val prop5: null + val prop5 = a + + // val prop6: null + val prop6 = a + 1 + + fun local() { + // val prop1: null + val prop1 = a + + // val prop2: null + val prop2 = a + 1 + } + + val b = { + // val prop3: null + val prop3 = a + + // val prop4: null + val prop4 = a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: null + val prop9 = a + + // val prop10: null + val prop10 = a + 1 + } + } + } +} + +fun foo() { + var a = 1 + + // val prop7: null + val prop7 = a + + // val prop8: null + val prop8 = a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.txt new file mode 100644 index 00000000000..f0da6ac1414 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.txt @@ -0,0 +1,20 @@ +package + +package test { + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/nonFinalProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/nonFinalProperty.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.fir.kt index 78035a28a04..030f33a5916 100644 --- a/compiler/testData/evaluate/constant/nonFinalProperty.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.fir.kt @@ -53,4 +53,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt new file mode 100644 index 00000000000..9da68d3aa23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt @@ -0,0 +1,56 @@ +package test + +// val prop1: null +val prop1 = A().a + +// val prop2: null +val prop2 = A().a + 1 + +class A() { + var a = 1 + + // val prop3: null + val prop3 = a + + // val prop4: null + val prop4 = a + 1 + + fun foo() { + // val prop5: null + val prop5 = A().a + + // val prop6: null + val prop6 = A().a + 1 + + val b = { + // val prop11: null + val prop11 = A().a + + // val prop12: null + val prop12 = A().a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: null + val prop9 = A().a + + // val prop10: null + val prop10 = A().a + 1 + } + } + } + +} + +fun foo() { + // val prop7: null + val prop7 = A().a + + // val prop8: null + val prop8 = A().a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.txt new file mode 100644 index 00000000000..7058646231b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.txt @@ -0,0 +1,25 @@ +package + +package test { + public val prop1: kotlin.Int + public val prop2: kotlin.Int + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public final var a: kotlin.Int + public final val prop3: kotlin.Int + public final val prop4: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/objectProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/objectProperty.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.fir.kt index 6132aecda7c..0be54d1331f 100644 --- a/compiler/testData/evaluate/constant/objectProperty.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.fir.kt @@ -45,4 +45,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt new file mode 100644 index 00000000000..53fa93452cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt @@ -0,0 +1,48 @@ +package test + +// val prop1: 1 +val prop1 = A.a + +// val prop2: 2 +val prop2 = A.a + 1 + +object A { + val a = 1 + + // val prop3: 1 + val prop3 = A.a + + + // val prop4: 2 + val prop4 = A.a + 1 +} + +fun foo() { + // val prop5: 1 + val prop5 = A.a + + // val prop6: 2 + val prop6 = A.a + 1 + + val b = { + // val prop11: 1 + val prop11 = A.a + + // val prop12: 2 + val prop12 = A.a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: 1 + val prop9 = A.a + + // val prop10: 2 + val prop10 = A.a + 1 + } + } +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.txt new file mode 100644 index 00000000000..ef5e8714045 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.txt @@ -0,0 +1,24 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.Int = 2 + public fun foo(): kotlin.Unit + + public object A { + private constructor A() + public final val a: kotlin.Int = 1 + public final val prop3: kotlin.Int = 1 + public final val prop4: kotlin.Int = 2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/strings.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.fir.kt similarity index 97% rename from compiler/testData/evaluate/constant/strings.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.fir.kt index 04e0cf9e2e8..7008dff6bfc 100644 --- a/compiler/testData/evaluate/constant/strings.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.fir.kt @@ -1,3 +1,4 @@ +// WITH_STDLIB package test enum class MyEnum { diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt new file mode 100644 index 00000000000..d12fc41d63f --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt @@ -0,0 +1,39 @@ +// WITH_STDLIB +package test + +enum class MyEnum { + A +} + +// val prop1: \"2\" +val prop1 = "${1 + 1}" + +// val prop2: null +val prop2 = "myEnum=${MyEnum.A}" + +// val prop3: \"1\" +val prop3 = "${1}" + +// val prop4: \"null\" +val prop4 = "${null}" + +// val prop5: \"1.0\" +val prop5 = "${1.toFloat()}" + +// val prop6: \"1.0\" +val prop6 = "${1.0}" + +// val prop7: null +val prop7 = "${Int::class.java}" + +// val prop8: \"a1.0\" +val prop8 = "a${1.toDouble()}" + +// val prop9: \"ab\" +val prop9 = "a" + "b" + +// val prop10: \"abb\" +val prop10 = prop9 + "b" + +// val prop11: 6 +val prop11 = "kotlin".length diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.txt new file mode 100644 index 00000000000..421aa900d2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.txt @@ -0,0 +1,34 @@ +package + +package test { + public val prop1: kotlin.String = "2" + public val prop10: kotlin.String = "abb" + public val prop11: kotlin.Int = 6 + public val prop2: kotlin.String + public val prop3: kotlin.String = "1" + public val prop4: kotlin.String = "null" + public val prop5: kotlin.String = "1.0" + public val prop6: kotlin.String = "1.0" + public val prop7: kotlin.String + public val prop8: kotlin.String = "a1.0" + public val prop9: kotlin.String = "ab" + + public final enum class MyEnum : kotlin.Enum { + enum entry A + + private constructor MyEnum() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: test.MyEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.MyEnum + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/evaluate/constant/topLevelVal.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/topLevelVal.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.fir.kt index 29a0a0105f5..23bab17ccdb 100644 --- a/compiler/testData/evaluate/constant/topLevelVal.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.fir.kt @@ -44,4 +44,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt new file mode 100644 index 00000000000..d0e135245e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt @@ -0,0 +1,47 @@ +package test + +val a = 1 + +// val prop1: 1 +val prop1 = a + +// val prop2: 2 +val prop2 = a + 1 + +class A { + // val prop3: 1 + val prop3 = a + + // val prop4: 2 + val prop4 = a + 1 + + val b = { + // val prop11: 1 + val prop11 = a + + // val prop12: 2 + val prop12 = a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: 1 + val prop9 = a + + // val prop10: 2 + val prop10 = a + 1 + } + } +} + +fun foo() { + // val prop5: 1 + val prop5 = a + + // val prop6: 2 + val prop6 = a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.txt new file mode 100644 index 00000000000..8dfa4bd9d29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.txt @@ -0,0 +1,26 @@ +package + +package test { + public val a: kotlin.Int = 1 + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.Int = 2 + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public final val b: () -> kotlin.Unit + public final val c: test.Foo + public final val prop3: kotlin.Int = 1 + public final val prop4: kotlin.Int = 2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/topLevelVar.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.fir.kt similarity index 99% rename from compiler/testData/evaluate/constant/topLevelVar.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.fir.kt index 717d8087726..03c11b7ec77 100644 --- a/compiler/testData/evaluate/constant/topLevelVar.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.fir.kt @@ -44,4 +44,4 @@ fun foo() { interface Foo { fun f() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt new file mode 100644 index 00000000000..ea67aa63ae3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt @@ -0,0 +1,47 @@ +package test + +var a = 1 + +// val prop1: null +val prop1 = a + +// val prop2: null +val prop2 = a + 1 + +class A { + // val prop3: null + val prop3 = a + + // val prop4: null + val prop4 = a + 1 + + val b = { + // val prop11: null + val prop11 = a + + // val prop12: null + val prop12 = a + 1 + } + + val c = object: Foo { + override fun f() { + // val prop9: null + val prop9 = a + + // val prop10: null + val prop10 = a + 1 + } + } +} + +fun foo() { + // val prop5: null + val prop5 = a + + // val prop6: null + val prop6 = a + 1 +} + +interface Foo { + fun f() +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.txt new file mode 100644 index 00000000000..5802a4ad636 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.txt @@ -0,0 +1,26 @@ +package + +package test { + public var a: kotlin.Int + public val prop1: kotlin.Int + public val prop2: kotlin.Int + public fun foo(): kotlin.Unit + + public final class A { + public constructor A() + public final val b: () -> kotlin.Unit + public final val c: test.Foo + public final val prop3: kotlin.Int + public final val prop4: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Foo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/evaluate/constant/unaryMinusIndepWoExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.fir.kt similarity index 100% rename from compiler/testData/evaluate/constant/unaryMinusIndepWoExpType.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt new file mode 100644 index 00000000000..b71ce59d263 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt @@ -0,0 +1,22 @@ +package test + +// val p1: -1 +val p1 = -1 + +// val p2: -1.toLong() +val p2 = -1.toLong() + +// val p3: -1.toByte() +val p3 = (-1).toByte() + +// val p3a: -1 +val p3a =-1.toByte() + +// val p4: -1 +val p4 = -1.toInt() + +// val p5: -1.toShort() +val p5 = (-1).toShort() + +// val p5a: -1 +val p5a = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.txt new file mode 100644 index 00000000000..9895c2aa53e --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.txt @@ -0,0 +1,11 @@ +package + +package test { + public val p1: kotlin.Int = -1 + public val p2: kotlin.Long = -1.toLong() + public val p3: kotlin.Byte = -1.toByte() + public val p3a: kotlin.Int = -1 + public val p4: kotlin.Int = -1 + public val p5: kotlin.Short = -1.toShort() + public val p5a: kotlin.Int = -1 +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.fir.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.fir.kt new file mode 100644 index 00000000000..bb3c530e11c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.fir.kt @@ -0,0 +1,63 @@ +package test + +// val p1: -1 +val p1: Int = -1 + +// val p2: -1.toLong() +val p2: Long = -1 + +// val p3: -1.toByte() +val p3: Byte = -1 + +// val p4: -1.toShort() +val p4: Short = -1 + +// val l1: -1.toLong() +val l1: Long = -1.toLong() + +// val l2: -1.toLong() +val l2: Byte = -1.toLong() + +// val l3: -1.toLong() +val l3: Int = -1.toLong() + +// val l4: -1.toLong() +val l4: Short = -1.toLong() + + +// val b1: -1 +val b1: Byte = -1.toByte() + +// val b2: -1 +val b2: Int = -1.toByte() + +// val b3: -1 +val b3: Long = -1.toByte() + +// val b4: -1 +val b4: Short = -1.toByte() + + +// val i1: -1 +val i1: Byte = -1.toInt() + +// val i2: -1 +val i2: Int = -1.toInt() + +// val i3: -1 +val i3: Long = -1.toInt() + +// val i4: -1 +val i4: Short = -1.toInt() + +// val s1: -1 +val s1: Byte = -1.toShort() + +// val s2: -1 +val s2: Int = -1.toShort() + +// val s3: -1 +val s3: Long = -1.toShort() + +// val s4: -1 +val s4: Short = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt new file mode 100644 index 00000000000..32e2be2d3e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt @@ -0,0 +1,63 @@ +package test + +// val p1: -1 +val p1: Int = -1 + +// val p2: -1.toLong() +val p2: Long = -1 + +// val p3: -1.toByte() +val p3: Byte = -1 + +// val p4: -1.toShort() +val p4: Short = -1 + +// val l1: -1.toLong() +val l1: Long = -1.toLong() + +// val l2: -1.toLong() +val l2: Byte = -1.toLong() + +// val l3: -1.toLong() +val l3: Int = -1.toLong() + +// val l4: -1.toLong() +val l4: Short = -1.toLong() + + +// val b1: -1 +val b1: Byte = -1.toByte() + +// val b2: -1 +val b2: Int = -1.toByte() + +// val b3: -1 +val b3: Long = -1.toByte() + +// val b4: -1 +val b4: Short = -1.toByte() + + +// val i1: -1 +val i1: Byte = -1.toInt() + +// val i2: -1 +val i2: Int = -1.toInt() + +// val i3: -1 +val i3: Long = -1.toInt() + +// val i4: -1 +val i4: Short = -1.toInt() + +// val s1: -1 +val s1: Byte = -1.toShort() + +// val s2: -1 +val s2: Int = -1.toShort() + +// val s3: -1 +val s3: Long = -1.toShort() + +// val s4: -1 +val s4: Short = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.txt new file mode 100644 index 00000000000..611bc940c75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.txt @@ -0,0 +1,24 @@ +package + +package test { + public val b1: kotlin.Byte = -1 + public val b2: kotlin.Int = -1 + public val b3: kotlin.Long = -1 + public val b4: kotlin.Short = -1 + public val i1: kotlin.Byte = -1 + public val i2: kotlin.Int = -1 + public val i3: kotlin.Long = -1 + public val i4: kotlin.Short = -1 + public val l1: kotlin.Long = -1.toLong() + public val l2: kotlin.Byte = -1.toLong() + public val l3: kotlin.Int = -1.toLong() + public val l4: kotlin.Short = -1.toLong() + public val p1: kotlin.Int = -1 + public val p2: kotlin.Long = -1.toLong() + public val p3: kotlin.Byte = -1.toByte() + public val p4: kotlin.Short = -1.toShort() + public val s1: kotlin.Byte = -1 + public val s2: kotlin.Int = -1 + public val s3: kotlin.Long = -1 + public val s4: kotlin.Short = -1 +} diff --git a/compiler/testData/evaluate/isPure/innerToType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.fir.kt similarity index 84% rename from compiler/testData/evaluate/isPure/innerToType.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.fir.kt index 4eda6cca3e5..c7097eacd51 100644 --- a/compiler/testData/evaluate/isPure/innerToType.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.fir.kt @@ -10,4 +10,4 @@ val prop2 = -1.toInt() val prop3 = 1 + 1.toByte() // val prop4: false -val prop4 = 1 + 1.toShort() + 1 \ No newline at end of file +val prop4 = 1 + 1.toShort() + 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt new file mode 100644 index 00000000000..49210099428 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt @@ -0,0 +1,13 @@ +package test + +// val prop1: false +val prop1 = 1.toLong() + 1 + +// val prop2: false +val prop2 = -1.toInt() + +// val prop3: false +val prop3 = 1 + 1.toByte() + +// val prop4: false +val prop4 = 1 + 1.toShort() + 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.txt new file mode 100644 index 00000000000..b666fa1f215 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.txt @@ -0,0 +1,8 @@ +package + +package test { + public val prop1: kotlin.Long = 2.toLong() + public val prop2: kotlin.Int = -1 + public val prop3: kotlin.Int = 2 + public val prop4: kotlin.Int = 3 +} diff --git a/compiler/testData/evaluate/isPure/namedConstants.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.fir.kt similarity index 77% rename from compiler/testData/evaluate/isPure/namedConstants.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.fir.kt index 3a1628a85ec..11f3ab8e918 100644 --- a/compiler/testData/evaluate/isPure/namedConstants.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.fir.kt @@ -6,4 +6,4 @@ val NAMED_CONSTANT = 1 val prop1 = NAMED_CONSTANT // val prop2: false -val prop2 = NAMED_CONSTANT + 1 \ No newline at end of file +val prop2 = NAMED_CONSTANT + 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt new file mode 100644 index 00000000000..d8287ff618b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt @@ -0,0 +1,9 @@ +package test + +val NAMED_CONSTANT = 1 + +// val prop1: false +val prop1 = NAMED_CONSTANT + +// val prop2: false +val prop2 = NAMED_CONSTANT + 1 diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.txt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.txt new file mode 100644 index 00000000000..a4cf2f2c8ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.txt @@ -0,0 +1,7 @@ +package + +package test { + public val NAMED_CONSTANT: kotlin.Int = 1 + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.Int = 2 +} diff --git a/compiler/testData/evaluate/isPure/toType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.fir.kt similarity index 100% rename from compiler/testData/evaluate/isPure/toType.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt new file mode 100644 index 00000000000..c30b9149740 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt @@ -0,0 +1,16 @@ +package test + +// val prop1: false +val prop1 = 1.toLong() + +// val prop2: false +val prop2 = 1.toInt() + +// val prop3: false +val prop3 = 1.toByte() + +// val prop4: false +val prop4 = 1.toShort() + +// val prop5: false +val prop5 = 1.toChar() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.txt new file mode 100644 index 00000000000..2af4feae34e --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.txt @@ -0,0 +1,9 @@ +package + +package test { + public val prop1: kotlin.Long = 1.toLong() + public val prop2: kotlin.Int = 1 + public val prop3: kotlin.Byte = 1.toByte() + public val prop4: kotlin.Short = 1.toShort() + public val prop5: kotlin.Char = \u0001 ('?') +} diff --git a/compiler/testData/evaluate/isPure/unaryMinusIndepWoExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.fir.kt similarity index 100% rename from compiler/testData/evaluate/isPure/unaryMinusIndepWoExpType.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt new file mode 100644 index 00000000000..c381b46f6eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt @@ -0,0 +1,16 @@ +package test + +// val p1: true +val p1 = -1 + +// val p2: false +val p2 = -1.toLong() + +// val p3: false +val p3 = -1.toByte() + +// val p4: false +val p4 = -1.toInt() + +// val p5: false +val p5 = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.txt new file mode 100644 index 00000000000..e905727e1fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.txt @@ -0,0 +1,9 @@ +package + +package test { + public val p1: kotlin.Int = -1 + public val p2: kotlin.Long = -1.toLong() + public val p3: kotlin.Int = -1 + public val p4: kotlin.Int = -1 + public val p5: kotlin.Int = -1 +} diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.fir.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.fir.kt new file mode 100644 index 00000000000..b94cb48bcea --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.fir.kt @@ -0,0 +1,63 @@ +package test + +// val p1: true +val p1: Int = -1 + +// val p2: true +val p2: Long = -1 + +// val p3: true +val p3: Byte = -1 + +// val p4: true +val p4: Short = -1 + +// val l1: false +val l1: Long = -1.toLong() + +// val l2: false +val l2: Byte = -1.toLong() + +// val l3: false +val l3: Int = -1.toLong() + +// val l4: false +val l4: Short = -1.toLong() + + +// val b1: false +val b1: Byte = -1.toByte() + +// val b2: false +val b2: Int = -1.toByte() + +// val b3: false +val b3: Long = -1.toByte() + +// val b4: false +val b4: Short = -1.toByte() + + +// val i1: false +val i1: Byte = -1.toInt() + +// val i2: false +val i2: Int = -1.toInt() + +// val i3: false +val i3: Long = -1.toInt() + +// val i4: false +val i4: Short = -1.toInt() + +// val s1: false +val s1: Byte = -1.toShort() + +// val s2: false +val s2: Int = -1.toShort() + +// val s3: false +val s3: Long = -1.toShort() + +// val s4: false +val s4: Short = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt new file mode 100644 index 00000000000..65ee5518e05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt @@ -0,0 +1,63 @@ +package test + +// val p1: true +val p1: Int = -1 + +// val p2: true +val p2: Long = -1 + +// val p3: true +val p3: Byte = -1 + +// val p4: true +val p4: Short = -1 + +// val l1: false +val l1: Long = -1.toLong() + +// val l2: false +val l2: Byte = -1.toLong() + +// val l3: false +val l3: Int = -1.toLong() + +// val l4: false +val l4: Short = -1.toLong() + + +// val b1: false +val b1: Byte = -1.toByte() + +// val b2: false +val b2: Int = -1.toByte() + +// val b3: false +val b3: Long = -1.toByte() + +// val b4: false +val b4: Short = -1.toByte() + + +// val i1: false +val i1: Byte = -1.toInt() + +// val i2: false +val i2: Int = -1.toInt() + +// val i3: false +val i3: Long = -1.toInt() + +// val i4: false +val i4: Short = -1.toInt() + +// val s1: false +val s1: Byte = -1.toShort() + +// val s2: false +val s2: Int = -1.toShort() + +// val s3: false +val s3: Long = -1.toShort() + +// val s4: false +val s4: Short = -1.toShort() diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.txt b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.txt new file mode 100644 index 00000000000..611bc940c75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.txt @@ -0,0 +1,24 @@ +package + +package test { + public val b1: kotlin.Byte = -1 + public val b2: kotlin.Int = -1 + public val b3: kotlin.Long = -1 + public val b4: kotlin.Short = -1 + public val i1: kotlin.Byte = -1 + public val i2: kotlin.Int = -1 + public val i3: kotlin.Long = -1 + public val i4: kotlin.Short = -1 + public val l1: kotlin.Long = -1.toLong() + public val l2: kotlin.Byte = -1.toLong() + public val l3: kotlin.Int = -1.toLong() + public val l4: kotlin.Short = -1.toLong() + public val p1: kotlin.Int = -1 + public val p2: kotlin.Long = -1.toLong() + public val p3: kotlin.Byte = -1.toByte() + public val p4: kotlin.Short = -1.toShort() + public val s1: kotlin.Byte = -1 + public val s2: kotlin.Int = -1 + public val s3: kotlin.Long = -1 + public val s4: kotlin.Short = -1 +} diff --git a/compiler/testData/evaluate/usesVariableAsConstant/NamedConstants.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.fir.kt similarity index 100% rename from compiler/testData/evaluate/usesVariableAsConstant/NamedConstants.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt new file mode 100644 index 00000000000..cca5d681520 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt @@ -0,0 +1,11 @@ +package test + +val x = 1 +val y = "a" + +// val prop1: true +val prop1 = x + +// val prop2: true +val prop2 = y + diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.txt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.txt new file mode 100644 index 00000000000..92ac1f8fb43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.txt @@ -0,0 +1,8 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.String = "a" + public val x: kotlin.Int = 1 + public val y: kotlin.String = "a" +} diff --git a/compiler/testData/evaluate/usesVariableAsConstant/OtherTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.fir.kt similarity index 88% rename from compiler/testData/evaluate/usesVariableAsConstant/OtherTypes.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.fir.kt index 2fce589d08a..6f731ca2563 100644 --- a/compiler/testData/evaluate/usesVariableAsConstant/OtherTypes.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.fir.kt @@ -19,4 +19,4 @@ val prop3 = "$x" val prop4 = intArrayOf(1, 2, 3) // val prop5: true -val prop5 = intArrayOf(1, 2, x, x) \ No newline at end of file +val prop5 = intArrayOf(1, 2, x, x) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt new file mode 100644 index 00000000000..d42a7c3c64c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt @@ -0,0 +1,22 @@ +package test + +enum class MyEnum { A, B } + +fun foo(): Boolean = true + +val x = 1 + +// val prop1: false +val prop1 = MyEnum.A + +// val prop2: null +val prop2 = foo() + +// val prop3: true +val prop3 = "$x" + +// val prop4: false +val prop4 = intArrayOf(1, 2, 3) + +// val prop5: true +val prop5 = intArrayOf(1, 2, x, x) diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.txt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.txt new file mode 100644 index 00000000000..383689b403d --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.txt @@ -0,0 +1,32 @@ +package + +package test { + public val prop1: test.MyEnum + public val prop2: kotlin.Boolean + public val prop3: kotlin.String = "1" + public val prop4: kotlin.IntArray + public val prop5: kotlin.IntArray + public val x: kotlin.Int = 1 + public fun foo(): kotlin.Boolean + + public final enum class MyEnum : kotlin.Enum { + enum entry A + + enum entry B + + private constructor MyEnum() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: test.MyEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.MyEnum + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/evaluate/usesVariableAsConstant/binaryTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.fir.kt similarity index 89% rename from compiler/testData/evaluate/usesVariableAsConstant/binaryTypes.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.fir.kt index fb22226574b..26153535d61 100644 --- a/compiler/testData/evaluate/usesVariableAsConstant/binaryTypes.kt +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.fir.kt @@ -4,10 +4,10 @@ val x = 1 val y = true // val prop1: false -val prop1 = 1 > 2 +val prop1 = 1 > 2 // val prop2: false -val prop2 = 2 + 3 +val prop2 = 2 + 3 // val prop3: true val prop3 = 2 + x diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt new file mode 100644 index 00000000000..5aae33a4f95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt @@ -0,0 +1,29 @@ +package test + +val x = 1 +val y = true + +// val prop1: false +val prop1 = 1 > 2 + +// val prop2: false +val prop2 = 2 + 3 + +// val prop3: true +val prop3 = 2 + x + +// val prop4: true +val prop4 = x < 2 + +// val prop5: true +val prop5 = y && true + +// val prop6: false +val prop6 = true && false || 2 > 1 + +// val prop7: true +val prop7 = x == 1 + +// val prop8: true +val prop8 = 1 / x + diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.txt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.txt new file mode 100644 index 00000000000..685794235d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.txt @@ -0,0 +1,14 @@ +package + +package test { + public val prop1: kotlin.Boolean = false + public val prop2: kotlin.Int = 5 + public val prop3: kotlin.Int = 3 + public val prop4: kotlin.Boolean = true + public val prop5: kotlin.Boolean = true + public val prop6: kotlin.Boolean = true + public val prop7: kotlin.Boolean = true + public val prop8: kotlin.Int = 1 + public val x: kotlin.Int = 1 + public val y: kotlin.Boolean = true +} diff --git a/compiler/testData/evaluate/usesVariableAsConstant/simpleTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.fir.kt similarity index 100% rename from compiler/testData/evaluate/usesVariableAsConstant/simpleTypes.kt rename to compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.fir.kt diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt new file mode 100644 index 00000000000..342bf4e0a6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt @@ -0,0 +1,23 @@ +package test + +// val prop1: false +val prop1 = 1 + +// val prop2: false +val prop2 = "hello" + +// val prop3: false +val prop3 = true + +// val prop4: false +val prop4 = false + +// val prop5: false +val prop5 = -7453 + +// val prop6: false +val prop6 = 3.56 + +// val prop7: false +val prop7 = 5464564L + diff --git a/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.txt b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.txt new file mode 100644 index 00000000000..46fb628366f --- /dev/null +++ b/compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.txt @@ -0,0 +1,11 @@ +package + +package test { + public val prop1: kotlin.Int = 1 + public val prop2: kotlin.String = "hello" + public val prop3: kotlin.Boolean = true + public val prop4: kotlin.Boolean = false + public val prop5: kotlin.Int = -7453 + public val prop6: kotlin.Double = 3.56.toDouble() + public val prop7: kotlin.Long = 5464564.toLong() +} diff --git a/compiler/testData/evaluate/constant/unaryMinusIndependentExpType.kt b/compiler/testData/evaluate/constant/unaryMinusIndependentExpType.kt deleted file mode 100644 index 8df0a8708a2..00000000000 --- a/compiler/testData/evaluate/constant/unaryMinusIndependentExpType.kt +++ /dev/null @@ -1,63 +0,0 @@ -package test - -// val p1: -1 -val p1: Int = -1 - -// val p2: -1.toLong() -val p2: Long = -1 - -// val p3: -1.toByte() -val p3: Byte = -1 - -// val p4: -1.toShort() -val p4: Short = -1 - -// val l1: -1.toLong() -val l1: Long = -1.toLong() - -// val l2: -1.toLong() -val l2: Byte = -1.toLong() - -// val l3: -1.toLong() -val l3: Int = -1.toLong() - -// val l4: -1.toLong() -val l4: Short = -1.toLong() - - -// val b1: -1 -val b1: Byte = -1.toByte() - -// val b2: -1 -val b2: Int = -1.toByte() - -// val b3: -1 -val b3: Long = -1.toByte() - -// val b4: -1 -val b4: Short = -1.toByte() - - -// val i1: -1 -val i1: Byte = -1.toInt() - -// val i2: -1 -val i2: Int = -1.toInt() - -// val i3: -1 -val i3: Long = -1.toInt() - -// val i4: -1 -val i4: Short = -1.toInt() - -// val s1: -1 -val s1: Byte = -1.toShort() - -// val s2: -1 -val s2: Int = -1.toShort() - -// val s3: -1 -val s3: Long = -1.toShort() - -// val s4: -1 -val s4: Short = -1.toShort() \ No newline at end of file diff --git a/compiler/testData/evaluate/isPure/unaryMinusIndependentExpType.kt b/compiler/testData/evaluate/isPure/unaryMinusIndependentExpType.kt deleted file mode 100644 index 747bca1b79f..00000000000 --- a/compiler/testData/evaluate/isPure/unaryMinusIndependentExpType.kt +++ /dev/null @@ -1,63 +0,0 @@ -package test - -// val p1: true -val p1: Int = -1 - -// val p2: true -val p2: Long = -1 - -// val p3: true -val p3: Byte = -1 - -// val p4: true -val p4: Short = -1 - -// val l1: false -val l1: Long = -1.toLong() - -// val l2: false -val l2: Byte = -1.toLong() - -// val l3: false -val l3: Int = -1.toLong() - -// val l4: false -val l4: Short = -1.toLong() - - -// val b1: false -val b1: Byte = -1.toByte() - -// val b2: false -val b2: Int = -1.toByte() - -// val b3: false -val b3: Long = -1.toByte() - -// val b4: false -val b4: Short = -1.toByte() - - -// val i1: false -val i1: Byte = -1.toInt() - -// val i2: false -val i2: Int = -1.toInt() - -// val i3: false -val i3: Long = -1.toInt() - -// val i4: false -val i4: Short = -1.toInt() - -// val s1: false -val s1: Byte = -1.toShort() - -// val s2: false -val s2: Int = -1.toShort() - -// val s3: false -val s3: Long = -1.toShort() - -// val s4: false -val s4: Short = -1.toShort() \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 13a2a787993..a962b3343ec 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -4732,6 +4732,226 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator") + @TestDataPath("$PROJECT_ROOT") + public class ConstantEvaluator { + @Test + public void testAllFilesPresentInConstantEvaluator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/constant") + @TestDataPath("$PROJECT_ROOT") + public class Constant { + @Test + public void testAllFilesPresentInConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/constant"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("classObjectProperty.kt") + public void testClassObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt"); + } + + @Test + @TestMetadata("compareTo.kt") + public void testCompareTo() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt"); + } + + @Test + @TestMetadata("differentTypes.kt") + public void testDifferentTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt"); + } + + @Test + @TestMetadata("divideByZero.kt") + public void testDivideByZero() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt"); + } + + @Test + @TestMetadata("equals.kt") + public void testEquals() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt"); + } + + @Test + @TestMetadata("exceptionWhenEvaluate.kt") + public void testExceptionWhenEvaluate() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt"); + } + + @Test + @TestMetadata("finalProperty.kt") + public void testFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt"); + } + + @Test + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt"); + } + + @Test + @TestMetadata("floatsAndDoubles.kt") + public void testFloatsAndDoubles() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt"); + } + + @Test + @TestMetadata("integer.kt") + public void testInteger() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt"); + } + + @Test + @TestMetadata("integerOperations.kt") + public void testIntegerOperations() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt"); + } + + @Test + @TestMetadata("integers.kt") + public void testIntegers() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt"); + } + + @Test + @TestMetadata("localVal.kt") + public void testLocalVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt"); + } + + @Test + @TestMetadata("localVar.kt") + public void testLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt"); + } + + @Test + @TestMetadata("nonFinalProperty.kt") + public void testNonFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt"); + } + + @Test + @TestMetadata("objectProperty.kt") + public void testObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt"); + } + + @Test + @TestMetadata("strings.kt") + public void testStrings() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt"); + } + + @Test + @TestMetadata("topLevelVal.kt") + public void testTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt"); + } + + @Test + @TestMetadata("topLevelVar.kt") + public void testTopLevelVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/isPure") + @TestDataPath("$PROJECT_ROOT") + public class IsPure { + @Test + public void testAllFilesPresentInIsPure() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/isPure"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("innerToType.kt") + public void testInnerToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt"); + } + + @Test + @TestMetadata("namedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt"); + } + + @Test + @TestMetadata("toType.kt") + public void testToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant") + @TestDataPath("$PROJECT_ROOT") + public class UsesVariableAsConstant { + @Test + public void testAllFilesPresentInUsesVariableAsConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("binaryTypes.kt") + public void testBinaryTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt"); + } + + @Test + @TestMetadata("NamedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt"); + } + + @Test + @TestMetadata("OtherTypes.kt") + public void testOtherTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt"); + } + + @Test + @TestMetadata("simpleTypes.kt") + public void testSimpleTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt index d21e04f13ea..800f031770f 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt @@ -7,10 +7,8 @@ package org.jetbrains.kotlin.test.directives import org.jetbrains.kotlin.test.backend.handlers.JvmBackendDiagnosticsHandler import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_JAVAC -import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability -import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.Any -import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.Global import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer +import org.jetbrains.kotlin.test.frontend.classic.handlers.ConstantValuesHandler object DiagnosticsDirectives : SimpleDirectivesContainer() { val WITH_NEW_INFERENCE by directive( @@ -77,4 +75,13 @@ object DiagnosticsDirectives : SimpleDirectivesContainer() { only if they are defined in testdata. """.trimIndent() ) + + val CHECK_COMPILE_TIME_VALUES by enumDirective( + description = """ + Enables ${ConstantValuesHandler::class} which renders values from constant + evaluator in meta infos. + + Value determines which context slice should be checked + """.trimIndent() + ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ConstantValuesHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ConstantValuesHandler.kt new file mode 100644 index 00000000000..87bff910637 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ConstantValuesHandler.kt @@ -0,0 +1,157 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test.frontend.classic.handlers + +import com.intellij.openapi.project.Project +import junit.framework.TestCase +import org.jetbrains.kotlin.codeMetaInfo.model.ParsedCodeMetaInfo +import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptor +import org.jetbrains.kotlin.incremental.components.NoLookupLocation +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtProperty +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DelegatingBindingTrace +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant +import org.jetbrains.kotlin.resolve.constants.StringValue +import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator +import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile +import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives +import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.CHECK_COMPILE_TIME_VALUES +import org.jetbrains.kotlin.test.directives.model.DirectivesContainer +import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.model.TestFile +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.globalMetadataInfoHandler + +class ConstantValuesHandler(testServices: TestServices) : ClassicFrontendAnalysisHandler(testServices) { + companion object { + private const val DEBUG_INFO_CONSTANT = "DEBUG_INFO_CONSTANT_VALUE" + private val propertyNameMatchingRegex = """val ([\w\d]+)(: .*)? =""".toRegex() + } + + enum class Mode { + Constant, + IsPure, + UsesVariableAsConstant + } + + override val directivesContainers: List + get() = listOf(DiagnosticsDirectives) + + private val metaInfoHandler = testServices.globalMetadataInfoHandler + + override fun processModule(module: TestModule, info: ClassicFrontendOutputArtifact) { + val mode = module.directives.singleOrZeroValue(CHECK_COMPILE_TIME_VALUES) ?: return + + for ((file, ktFile) in info.ktFiles) { + processFile(file, ktFile, info, mode) + } + } + + private fun processFile(file: TestFile, ktFile: KtFile, info: ClassicFrontendOutputArtifact, mode: Mode) { + val expectedMetaInfos = metaInfoHandler.getExistingMetaInfosForFile(file).filter { it.tag == DEBUG_INFO_CONSTANT } + val fileText = ktFile.text + val packageFragmentDescriptor = info.analysisResult.moduleDescriptor.findPackageFragmentForFile(ktFile) ?: return + val bindingContext = info.analysisResult.bindingContext + val project = info.project + + val actualMetaInfos = mutableListOf() + for (expectedMetaInfo in expectedMetaInfos) { + val start = expectedMetaInfo.start + val end = expectedMetaInfo.end + + val markedText = fileText.substring(start, end) + val propertyName = propertyNameMatchingRegex.find(markedText)?.groups?.get(1)?.value ?: continue + val propertyDescriptor = getPropertyDescriptor(packageFragmentDescriptor, propertyName) + ?: getLocalVarDescriptor(bindingContext, propertyName) ?: continue + val actualValue = when (mode) { + Mode.Constant -> checkConstant(propertyDescriptor) + Mode.IsPure -> checkIsPure(bindingContext, propertyDescriptor, project) + Mode.UsesVariableAsConstant -> checkVariableAsConstant(bindingContext, propertyDescriptor, project) + } + + actualMetaInfos += ParsedCodeMetaInfo( + start, + end, + attributes = mutableListOf(), + tag = DEBUG_INFO_CONSTANT, + description = actualValue + ) + } + + metaInfoHandler.addMetadataInfosForFile(file, actualMetaInfos) + } + + override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} + + private fun checkConstant(variableDescriptor: VariableDescriptor): String { + val compileTimeConstant = variableDescriptor.compileTimeInitializer + return if (compileTimeConstant is StringValue) { + "\\\"${compileTimeConstant.value}\\\"" + } else { + "$compileTimeConstant" + } + } + + private fun checkIsPure(bindingContext: BindingContext, variableDescriptor: VariableDescriptor, project: Project): String { + return evaluateInitializer(bindingContext, variableDescriptor, project)?.isPure.toString() + } + + private fun checkVariableAsConstant(bindingContext: BindingContext, variableDescriptor: VariableDescriptor, project: Project): String { + return evaluateInitializer(bindingContext, variableDescriptor, project)?.usesVariableAsConstant.toString() + } + + private fun evaluateInitializer(context: BindingContext, property: VariableDescriptor, project: Project): CompileTimeConstant<*>? { + val propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property) as KtProperty + return ConstantExpressionEvaluator(property.module, LanguageVersionSettingsImpl.DEFAULT, project).evaluateExpression( + propertyDeclaration.initializer!!, + DelegatingBindingTrace(context, "trace for evaluating compile time constant"), + property.type + ) + } + + private fun getPropertyDescriptor(packageView: PackageFragmentDescriptor, name: String): PropertyDescriptor? { + val propertyName = Name.identifier(name) + val memberScope = packageView.getMemberScope() + var properties: Collection = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST) + if (properties.isEmpty()) { + for (descriptor in DescriptorUtils.getAllDescriptors(memberScope)) { + if (descriptor is ClassDescriptor) { + val classProperties: Collection = descriptor.getMemberScope(emptyList()) + .getContributedVariables(propertyName, NoLookupLocation.FROM_TEST) + if (!classProperties.isEmpty()) { + properties = classProperties + break + } + } + } + } + if (properties.size != 1) { + return null + } + return properties.iterator().next() + } + + private fun getLocalVarDescriptor(context: BindingContext, name: String): VariableDescriptor? { + for (descriptor in context.getSliceContents(BindingContext.VARIABLE).values) { + if (descriptor.name.asString() == name) { + return descriptor + } + } + TestCase.fail("Failed to find local variable $name") + return null + } +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt index a6ff3661093..bb36a32969b 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.config.ExplicitApiMode import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives +import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.CHECK_COMPILE_TIME_VALUES import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.DIAGNOSTICS import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.REPORT_JVM_DIAGNOSTICS_ON_FRONTEND import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JDK_KIND @@ -17,12 +17,10 @@ import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirective import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_REFLECT import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.EXPLICIT_API_MODE +import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.LANGUAGE import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.USE_EXPERIMENTAL import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade -import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler -import org.jetbrains.kotlin.test.frontend.classic.handlers.DeclarationsDumpHandler -import org.jetbrains.kotlin.test.frontend.classic.handlers.FirTestDataConsistencyHandler -import org.jetbrains.kotlin.test.frontend.classic.handlers.OldNewInferenceMetaInfoProcessor +import org.jetbrains.kotlin.test.frontend.classic.handlers.* import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator @@ -76,6 +74,7 @@ abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() { useFrontendHandlers( ::DeclarationsDumpHandler, ::ClassicDiagnosticsHandler, + ::ConstantValuesHandler ) useAfterAnalysisCheckers(::FirTestDataConsistencyHandler) @@ -112,5 +111,30 @@ abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() { +WITH_REFLECT } } + + // ----------------------- constant evaluation tests ----------------------- + forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/*") { + defaultDirectives { + LANGUAGE with "-ApproximateIntegerLiteralTypesInReceiverPosition" + } + } + + forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/constant/*") { + defaultDirectives { + CHECK_COMPILE_TIME_VALUES with ConstantValuesHandler.Mode.Constant + } + } + + forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/isPure/*") { + defaultDirectives { + CHECK_COMPILE_TIME_VALUES with ConstantValuesHandler.Mode.IsPure + } + } + + forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/*") { + defaultDirectives { + CHECK_COMPILE_TIME_VALUES with ConstantValuesHandler.Mode.UsesVariableAsConstant + } + } } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constants/evaluate/AbstractCompileTimeConstantEvaluatorTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constants/evaluate/AbstractCompileTimeConstantEvaluatorTest.kt deleted file mode 100644 index 265d513489a..00000000000 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constants/evaluate/AbstractCompileTimeConstantEvaluatorTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants.evaluate - -import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl -import org.jetbrains.kotlin.descriptors.VariableDescriptor -import org.jetbrains.kotlin.psi.KtProperty -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.DelegatingBindingTrace -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.resolve.annotation.AbstractAnnotationDescriptorResolveTest -import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant -import org.jetbrains.kotlin.resolve.constants.StringValue -import org.jetbrains.kotlin.resolve.descriptorUtil.module -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File -import java.util.regex.Pattern - -abstract class AbstractCompileTimeConstantEvaluatorTest : AbstractAnnotationDescriptorResolveTest() { - - // Test directives should look like [// val testedPropertyName: expectedValue] - fun doConstantTest(path: String) { - doTest(path) { - property, _ -> - val compileTimeConstant = property.compileTimeInitializer - if (compileTimeConstant is StringValue) { - "\\\"${compileTimeConstant.value}\\\"" - } else { - "$compileTimeConstant" - } - } - } - - // Test directives should look like [// val testedPropertyName: expectedValue] - fun doIsPureTest(path: String) { - doTest(path) { - property, context -> - evaluateInitializer(context, property)?.isPure.toString() - } - } - - // Test directives should look like [// val testedPropertyName: expectedValue] - fun doUsesVariableAsConstantTest(path: String) { - doTest(path) { - property, context -> - evaluateInitializer(context, property)?.usesVariableAsConstant.toString() - } - } - - private fun evaluateInitializer(context: BindingContext, property: VariableDescriptor): CompileTimeConstant<*>? { - val propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property) as KtProperty - return ConstantExpressionEvaluator(property.module, LanguageVersionSettingsImpl.DEFAULT, project).evaluateExpression( - propertyDeclaration.initializer!!, - DelegatingBindingTrace(context, "trace for evaluating compile time constant"), - property.type - ) - } - - private fun doTest(path: String, getValueToTest: (VariableDescriptor, BindingContext) -> String) { - val myFile = File(path) - val fileText = FileUtil.loadFile(myFile, true) - val packageView = getPackage(fileText) - - val propertiesForTest = getObjectsToTest(fileText) - - val expectedActual = arrayListOf>() - - for (propertyName in propertiesForTest) { - val expectedPropertyPrefix = "// val ${propertyName}: " - val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, expectedPropertyPrefix) - assertNotNull(expected, "Failed to find expected directive: $expectedPropertyPrefix") - - val property = AbstractAnnotationDescriptorResolveTest.getPropertyDescriptor(packageView, propertyName, false) - ?: AbstractAnnotationDescriptorResolveTest.getLocalVarDescriptor(context!!, propertyName) - - val testedObject = getValueToTest(property, context!!) - expectedActual.add(expectedPropertyPrefix + expected!! to expectedPropertyPrefix + testedObject) - } - - var actualFileText = fileText - for ((expected, actual) in expectedActual) { - assert(actualFileText.contains(expected)) { "File text should contain $expected" } - actualFileText = actualFileText.replace(expected, actual) - } - - KotlinTestUtils.assertEqualsToFile(myFile, actualFileText) - } - - fun getObjectsToTest(fileText: String): List { - return InTextDirectivesUtils.findListWithPrefixes(fileText, "// val").map { - val matcher = pattern.matcher(it) - if (matcher.find()) { - matcher.group(0) ?: "Couldn't match tested object $it" - } else "Couldn't match tested object $it" - } - } - - companion object { - val pattern = Pattern.compile(".+(?=:)") - } -} diff --git a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt index 876791809fa..5bcc51c8c6b 100644 --- a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt +++ b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt @@ -47,7 +47,6 @@ import org.jetbrains.kotlin.repl.AbstractReplInterpreterTest import org.jetbrains.kotlin.resolve.AbstractResolveTest import org.jetbrains.kotlin.resolve.calls.AbstractResolvedCallsTest import org.jetbrains.kotlin.resolve.calls.AbstractResolvedConstructorDelegationCallsTests -import org.jetbrains.kotlin.resolve.constants.evaluate.AbstractCompileTimeConstantEvaluatorTest import org.jetbrains.kotlin.resolve.constraintSystem.AbstractConstraintSystemTest import org.jetbrains.kotlin.serialization.AbstractLocalClassProtoTest import org.jetbrains.kotlin.test.TargetBackend @@ -304,12 +303,6 @@ fun generateJUnit3CompilerTests(args: Array) { model("cfgVariablesWithStdLib", testMethod = "doTestWithStdLib") } - testClass { - model("evaluate/constant", testMethod = "doConstantTest") - model("evaluate/isPure", testMethod = "doIsPureTest") - model("evaluate/usesVariableAsConstant", testMethod = "doUsesVariableAsConstantTest") - } - testClass { model("asJava/lightClasses", excludeDirs = listOf("local", "ideRegression"), pattern = KT_OR_KTS_WITHOUT_DOTS_IN_NAME) } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/resolve/constants/evaluate/CompileTimeConstantEvaluatorTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/resolve/constants/evaluate/CompileTimeConstantEvaluatorTestGenerated.java deleted file mode 100644 index 0b6c06265b9..00000000000 --- a/compiler/tests-gen/org/jetbrains/kotlin/resolve/constants/evaluate/CompileTimeConstantEvaluatorTestGenerated.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.resolve.constants.evaluate; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.util.KtTestUtil; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@RunWith(JUnit3RunnerWithInners.class) -public class CompileTimeConstantEvaluatorTestGenerated extends AbstractCompileTimeConstantEvaluatorTest { - @TestMetadata("compiler/testData/evaluate/constant") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Constant extends AbstractCompileTimeConstantEvaluatorTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doConstantTest, this, testDataFilePath); - } - - public void testAllFilesPresentInConstant() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/evaluate/constant"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("classObjectProperty.kt") - public void testClassObjectProperty() throws Exception { - runTest("compiler/testData/evaluate/constant/classObjectProperty.kt"); - } - - @TestMetadata("compareTo.kt") - public void testCompareTo() throws Exception { - runTest("compiler/testData/evaluate/constant/compareTo.kt"); - } - - @TestMetadata("differentTypes.kt") - public void testDifferentTypes() throws Exception { - runTest("compiler/testData/evaluate/constant/differentTypes.kt"); - } - - @TestMetadata("divideByZero.kt") - public void testDivideByZero() throws Exception { - runTest("compiler/testData/evaluate/constant/divideByZero.kt"); - } - - @TestMetadata("equals.kt") - public void testEquals() throws Exception { - runTest("compiler/testData/evaluate/constant/equals.kt"); - } - - @TestMetadata("exceptionWhenEvaluate.kt") - public void testExceptionWhenEvaluate() throws Exception { - runTest("compiler/testData/evaluate/constant/exceptionWhenEvaluate.kt"); - } - - @TestMetadata("finalProperty.kt") - public void testFinalProperty() throws Exception { - runTest("compiler/testData/evaluate/constant/finalProperty.kt"); - } - - @TestMetadata("float.kt") - public void testFloat() throws Exception { - runTest("compiler/testData/evaluate/constant/float.kt"); - } - - @TestMetadata("floatsAndDoubles.kt") - public void testFloatsAndDoubles() throws Exception { - runTest("compiler/testData/evaluate/constant/floatsAndDoubles.kt"); - } - - @TestMetadata("integer.kt") - public void testInteger() throws Exception { - runTest("compiler/testData/evaluate/constant/integer.kt"); - } - - @TestMetadata("integerOperations.kt") - public void testIntegerOperations() throws Exception { - runTest("compiler/testData/evaluate/constant/integerOperations.kt"); - } - - @TestMetadata("integers.kt") - public void testIntegers() throws Exception { - runTest("compiler/testData/evaluate/constant/integers.kt"); - } - - @TestMetadata("localVal.kt") - public void testLocalVal() throws Exception { - runTest("compiler/testData/evaluate/constant/localVal.kt"); - } - - @TestMetadata("localVar.kt") - public void testLocalVar() throws Exception { - runTest("compiler/testData/evaluate/constant/localVar.kt"); - } - - @TestMetadata("nonFinalProperty.kt") - public void testNonFinalProperty() throws Exception { - runTest("compiler/testData/evaluate/constant/nonFinalProperty.kt"); - } - - @TestMetadata("objectProperty.kt") - public void testObjectProperty() throws Exception { - runTest("compiler/testData/evaluate/constant/objectProperty.kt"); - } - - @TestMetadata("strings.kt") - public void testStrings() throws Exception { - runTest("compiler/testData/evaluate/constant/strings.kt"); - } - - @TestMetadata("topLevelVal.kt") - public void testTopLevelVal() throws Exception { - runTest("compiler/testData/evaluate/constant/topLevelVal.kt"); - } - - @TestMetadata("topLevelVar.kt") - public void testTopLevelVar() throws Exception { - runTest("compiler/testData/evaluate/constant/topLevelVar.kt"); - } - - @TestMetadata("unaryMinusIndepWoExpType.kt") - public void testUnaryMinusIndepWoExpType() throws Exception { - runTest("compiler/testData/evaluate/constant/unaryMinusIndepWoExpType.kt"); - } - - @TestMetadata("unaryMinusIndependentExpType.kt") - public void testUnaryMinusIndependentExpType() throws Exception { - runTest("compiler/testData/evaluate/constant/unaryMinusIndependentExpType.kt"); - } - } - - @TestMetadata("compiler/testData/evaluate/isPure") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class IsPure extends AbstractCompileTimeConstantEvaluatorTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doIsPureTest, this, testDataFilePath); - } - - public void testAllFilesPresentInIsPure() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/evaluate/isPure"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("innerToType.kt") - public void testInnerToType() throws Exception { - runTest("compiler/testData/evaluate/isPure/innerToType.kt"); - } - - @TestMetadata("namedConstants.kt") - public void testNamedConstants() throws Exception { - runTest("compiler/testData/evaluate/isPure/namedConstants.kt"); - } - - @TestMetadata("toType.kt") - public void testToType() throws Exception { - runTest("compiler/testData/evaluate/isPure/toType.kt"); - } - - @TestMetadata("unaryMinusIndepWoExpType.kt") - public void testUnaryMinusIndepWoExpType() throws Exception { - runTest("compiler/testData/evaluate/isPure/unaryMinusIndepWoExpType.kt"); - } - - @TestMetadata("unaryMinusIndependentExpType.kt") - public void testUnaryMinusIndependentExpType() throws Exception { - runTest("compiler/testData/evaluate/isPure/unaryMinusIndependentExpType.kt"); - } - } - - @TestMetadata("compiler/testData/evaluate/usesVariableAsConstant") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class UsesVariableAsConstant extends AbstractCompileTimeConstantEvaluatorTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doUsesVariableAsConstantTest, this, testDataFilePath); - } - - public void testAllFilesPresentInUsesVariableAsConstant() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/evaluate/usesVariableAsConstant"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("binaryTypes.kt") - public void testBinaryTypes() throws Exception { - runTest("compiler/testData/evaluate/usesVariableAsConstant/binaryTypes.kt"); - } - - @TestMetadata("NamedConstants.kt") - public void testNamedConstants() throws Exception { - runTest("compiler/testData/evaluate/usesVariableAsConstant/NamedConstants.kt"); - } - - @TestMetadata("OtherTypes.kt") - public void testOtherTypes() throws Exception { - runTest("compiler/testData/evaluate/usesVariableAsConstant/OtherTypes.kt"); - } - - @TestMetadata("simpleTypes.kt") - public void testSimpleTypes() throws Exception { - runTest("compiler/testData/evaluate/usesVariableAsConstant/simpleTypes.kt"); - } - } -} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 9d4855739fc..800faf9a970 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -4726,6 +4726,226 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator") + @TestDataPath("$PROJECT_ROOT") + public class ConstantEvaluator { + @Test + public void testAllFilesPresentInConstantEvaluator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/constant") + @TestDataPath("$PROJECT_ROOT") + public class Constant { + @Test + public void testAllFilesPresentInConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/constant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("classObjectProperty.kt") + public void testClassObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/classObjectProperty.kt"); + } + + @Test + @TestMetadata("compareTo.kt") + public void testCompareTo() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/compareTo.kt"); + } + + @Test + @TestMetadata("differentTypes.kt") + public void testDifferentTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/differentTypes.kt"); + } + + @Test + @TestMetadata("divideByZero.kt") + public void testDivideByZero() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/divideByZero.kt"); + } + + @Test + @TestMetadata("equals.kt") + public void testEquals() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/equals.kt"); + } + + @Test + @TestMetadata("exceptionWhenEvaluate.kt") + public void testExceptionWhenEvaluate() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/exceptionWhenEvaluate.kt"); + } + + @Test + @TestMetadata("finalProperty.kt") + public void testFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/finalProperty.kt"); + } + + @Test + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/float.kt"); + } + + @Test + @TestMetadata("floatsAndDoubles.kt") + public void testFloatsAndDoubles() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/floatsAndDoubles.kt"); + } + + @Test + @TestMetadata("integer.kt") + public void testInteger() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integer.kt"); + } + + @Test + @TestMetadata("integerOperations.kt") + public void testIntegerOperations() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integerOperations.kt"); + } + + @Test + @TestMetadata("integers.kt") + public void testIntegers() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/integers.kt"); + } + + @Test + @TestMetadata("localVal.kt") + public void testLocalVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVal.kt"); + } + + @Test + @TestMetadata("localVar.kt") + public void testLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/localVar.kt"); + } + + @Test + @TestMetadata("nonFinalProperty.kt") + public void testNonFinalProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/nonFinalProperty.kt"); + } + + @Test + @TestMetadata("objectProperty.kt") + public void testObjectProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/objectProperty.kt"); + } + + @Test + @TestMetadata("strings.kt") + public void testStrings() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/strings.kt"); + } + + @Test + @TestMetadata("topLevelVal.kt") + public void testTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVal.kt"); + } + + @Test + @TestMetadata("topLevelVar.kt") + public void testTopLevelVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/topLevelVar.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/constant/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/isPure") + @TestDataPath("$PROJECT_ROOT") + public class IsPure { + @Test + public void testAllFilesPresentInIsPure() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/isPure"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("innerToType.kt") + public void testInnerToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/innerToType.kt"); + } + + @Test + @TestMetadata("namedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/namedConstants.kt"); + } + + @Test + @TestMetadata("toType.kt") + public void testToType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/toType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndepWoExpType.kt") + public void testUnaryMinusIndepWoExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndepWoExpType.kt"); + } + + @Test + @TestMetadata("unaryMinusIndependentExpType.kt") + public void testUnaryMinusIndependentExpType() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/isPure/unaryMinusIndependentExpType.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant") + @TestDataPath("$PROJECT_ROOT") + public class UsesVariableAsConstant { + @Test + public void testAllFilesPresentInUsesVariableAsConstant() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("binaryTypes.kt") + public void testBinaryTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/binaryTypes.kt"); + } + + @Test + @TestMetadata("NamedConstants.kt") + public void testNamedConstants() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/NamedConstants.kt"); + } + + @Test + @TestMetadata("OtherTypes.kt") + public void testOtherTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/OtherTypes.kt"); + } + + @Test + @TestMetadata("simpleTypes.kt") + public void testSimpleTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/constantEvaluator/usesVariableAsConstant/simpleTypes.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency") @TestDataPath("$PROJECT_ROOT")