From 20d8e6607d7763666027c7cdc46b74c1e053700e Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Mon, 22 Nov 2021 22:37:13 +0300 Subject: [PATCH] Add new diagnostic tests to check new rules for const modifier --- ...irOldFrontendDiagnosticsTestGenerated.java | 24 +++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 24 +++++++++ .../modifiers/const/enumConstName.fir.kt | 8 +++ .../tests/modifiers/const/enumConstName.kt | 8 +++ .../tests/modifiers/const/enumConstName.txt | 31 +++++++++++ .../tests/modifiers/const/ifConstVal.fir.kt | 22 ++++++++ .../tests/modifiers/const/ifConstVal.kt | 22 ++++++++ .../tests/modifiers/const/ifConstVal.txt | 13 +++++ .../tests/modifiers/const/kCallable.fir.kt | 18 +++++++ .../tests/modifiers/const/kCallable.kt | 18 +++++++ .../tests/modifiers/const/kCallable.txt | 21 ++++++++ .../tests/modifiers/const/stdlibConstFun.kt | 54 +++++++++++++++++++ .../tests/modifiers/const/stdlibConstFun.txt | 44 +++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 24 +++++++++ 14 files changed, 331 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/enumConstName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/enumConstName.txt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.txt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/kCallable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/kCallable.txt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.txt 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 f103fd89304..8f4bc8e2391 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 @@ -20057,6 +20057,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/modifiers/const/constInteraction.kt"); } + @Test + @TestMetadata("enumConstName.kt") + public void testEnumConstName() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt"); + } + @Test @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { @@ -20069,6 +20075,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.kt"); } + @Test + @TestMetadata("ifConstVal.kt") + public void testIfConstVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt"); + } + + @Test + @TestMetadata("kCallable.kt") + public void testKCallable() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt"); + } + @Test @TestMetadata("kt12248.kt") public void testKt12248() throws Exception { @@ -20081,6 +20099,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/modifiers/const/kt15913.kt"); } + @Test + @TestMetadata("stdlibConstFun.kt") + public void testStdlibConstFun() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt"); + } + @Test @TestMetadata("types.kt") public void testTypes() throws Exception { 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 a9575463840..94bb2e3fb7d 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 @@ -20057,6 +20057,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/modifiers/const/constInteraction.kt"); } + @Test + @TestMetadata("enumConstName.kt") + public void testEnumConstName() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt"); + } + @Test @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { @@ -20069,6 +20075,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.kt"); } + @Test + @TestMetadata("ifConstVal.kt") + public void testIfConstVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt"); + } + + @Test + @TestMetadata("kCallable.kt") + public void testKCallable() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt"); + } + @Test @TestMetadata("kt12248.kt") public void testKt12248() throws Exception { @@ -20081,6 +20099,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/modifiers/const/kt15913.kt"); } + @Test + @TestMetadata("stdlibConstFun.kt") + public void testStdlibConstFun() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt"); + } + @Test @TestMetadata("types.kt") public void testTypes() throws Exception { diff --git a/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.fir.kt new file mode 100644 index 00000000000..142c5ab708d --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.fir.kt @@ -0,0 +1,8 @@ +enum class EnumClass { + OK, VALUE, anotherValue, WITH_UNDERSCORE +} + +const val name1 = EnumClass.OK.name +const val name2 = EnumClass.VALUE.name +const val name3 = EnumClass.anotherValue.name +const val name4 = EnumClass.WITH_UNDERSCORE.name \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt new file mode 100644 index 00000000000..645ac89b918 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt @@ -0,0 +1,8 @@ +enum class EnumClass { + OK, VALUE, anotherValue, WITH_UNDERSCORE +} + +const val name1 = EnumClass.OK.name +const val name2 = EnumClass.VALUE.name +const val name3 = EnumClass.anotherValue.name +const val name4 = EnumClass.WITH_UNDERSCORE.name diff --git a/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.txt b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.txt new file mode 100644 index 00000000000..4ad4db9890b --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/enumConstName.txt @@ -0,0 +1,31 @@ +package + +public const val name1: kotlin.String +public const val name2: kotlin.String +public const val name3: kotlin.String +public const val name4: kotlin.String + +public final enum class EnumClass : kotlin.Enum { + enum entry OK + + enum entry VALUE + + enum entry anotherValue + + enum entry WITH_UNDERSCORE + + private constructor EnumClass() + @kotlin.internal.IntrinsicConstEvaluation 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: EnumClass): 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): EnumClass + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.fir.kt new file mode 100644 index 00000000000..51410485584 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.fir.kt @@ -0,0 +1,22 @@ +const val flag = true +const val value = 10 + +const val condition = if (flag) "True" else "Error" +const val withWhen = when (flag) { + true -> "True" + else -> "Error" +} +const val withWhen2 = when { + flag == true -> "True" + else -> "Error" +} +const val withWhen3 = when(value) { + 10 -> "1" + 100 -> "2" + else -> "3" +} +const val multibranchIf = if (value == 100) 1 else if (value == 1000) 2 else 3 + +val nonConstFlag = true +const val errorConstIf = if (nonConstFlag) 1 else 2 +const val errorBranch = if (flag) nonConstFlag else false diff --git a/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt new file mode 100644 index 00000000000..63c8b77fa97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt @@ -0,0 +1,22 @@ +const val flag = true +const val value = 10 + +const val condition = if (flag) "True" else "Error" +const val withWhen = when (flag) { + true -> "True" + else -> "Error" +} +const val withWhen2 = when { + flag == true -> "True" + else -> "Error" +} +const val withWhen3 = when(value) { + 10 -> "1" + 100 -> "2" + else -> "3" +} +const val multibranchIf = if (value == 100) 1 else if (value == 1000) 2 else 3 + +val nonConstFlag = true +const val errorConstIf = if (nonConstFlag) 1 else 2 +const val errorBranch = if (flag) nonConstFlag else false diff --git a/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.txt b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.txt new file mode 100644 index 00000000000..6889f80d22b --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.txt @@ -0,0 +1,13 @@ +package + +public const val condition: kotlin.String +public const val errorBranch: kotlin.Boolean +public const val errorConstIf: kotlin.Int +public const val flag: kotlin.Boolean = true +public const val multibranchIf: kotlin.Int +public val nonConstFlag: kotlin.Boolean = true +public const val value: kotlin.Int = 10 +public const val withWhen: kotlin.String +public const val withWhen2: kotlin.String +public const val withWhen3: kotlin.String + diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kCallable.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.fir.kt new file mode 100644 index 00000000000..6e28a62ff80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.fir.kt @@ -0,0 +1,18 @@ +class SomeClassWithName(val property: Int) { + val anotherProperty: String = "" + + fun foo() {} + fun bar(a: Int, b: Double): String = "" +} + +const val className = ::SomeClassWithName.name +const val propName = SomeClassWithName::property.name +const val anotherPropName = SomeClassWithName::anotherProperty.name +const val fooName = SomeClassWithName::foo.name +const val barName = SomeClassWithName::bar.name + +const val stringClassName = ::String.name +const val lengthPropName = String::length.name + +const val errorAccess = SomeClassWithName(1)::property.name +const val errorPlus = "" + ::SomeClassWithName.property diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt new file mode 100644 index 00000000000..1c7d96d658b --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt @@ -0,0 +1,18 @@ +class SomeClassWithName(val property: Int) { + val anotherProperty: String = "" + + fun foo() {} + fun bar(a: Int, b: Double): String = "" +} + +const val className = ::SomeClassWithName.name +const val propName = SomeClassWithName::property.name +const val anotherPropName = SomeClassWithName::anotherProperty.name +const val fooName = SomeClassWithName::foo.name +const val barName = SomeClassWithName::bar.name + +const val stringClassName = ::String.name +const val lengthPropName = String::length.name + +const val errorAccess = SomeClassWithName(1)::property.name +const val errorPlus = "" + ::SomeClassWithName.property diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kCallable.txt b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.txt new file mode 100644 index 00000000000..90f05d12aab --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/kCallable.txt @@ -0,0 +1,21 @@ +package + +public const val anotherPropName: kotlin.String +public const val barName: kotlin.String +public const val className: kotlin.String +public const val errorAccess: kotlin.String +public const val fooName: kotlin.String +public const val lengthPropName: kotlin.String +public const val propName: kotlin.String +public const val stringClassName: kotlin.String + +public final class SomeClassWithName { + public constructor SomeClassWithName(/*0*/ property: kotlin.Int) + public final val anotherProperty: kotlin.String = "" + public final val property: kotlin.Int + public final fun bar(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Double): kotlin.String + 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 +} diff --git a/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt b/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt new file mode 100644 index 00000000000..fd653bfc152 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt @@ -0,0 +1,54 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +const val byte: Byte = 1 +const val short: Short = 2 +const val int: Int = 3 +const val long: Long = 4L +const val float: Float = 5f +const val double: Double = 6.0 + +val byteFloorByte = byte.floorDiv(byte) +val byteFloorShort = byte.floorDiv(short) +val byteFloorInt = byte.floorDiv(int) +val byteFloorLong = byte.floorDiv(long) + +val shortFloorByte = byte.floorDiv(byte) +val shortFloorShort = byte.floorDiv(short) +val shortFloorInt = byte.floorDiv(int) +val shortFloorLong = byte.floorDiv(long) + +val intFloorByte = byte.floorDiv(byte) +val intFloorShort = byte.floorDiv(short) +val intFloorInt = byte.floorDiv(int) +val intFloorLong = byte.floorDiv(long) + +val longFloorByte = byte.floorDiv(byte) +val longFloorShort = byte.floorDiv(short) +val longFloorInt = byte.floorDiv(int) +val longFloorLong = byte.floorDiv(long) + +val byteModByte = byte.mod(byte) +val byteModShort = byte.mod(short) +val byteModInt = byte.mod(int) +val byteModLong = byte.mod(long) + +val shortModByte = byte.mod(byte) +val shortModShort = byte.mod(short) +val shortModInt = byte.mod(int) +val shortModLong = byte.mod(long) + +val intModByte = byte.mod(byte) +val intModShort = byte.mod(short) +val intModInt = byte.mod(int) +val intModLong = byte.mod(long) + +val longModByte = byte.mod(byte) +val longModShort = byte.mod(short) +val longModInt = byte.mod(int) +val longModLong = byte.mod(long) + +val floatModFloat = float.mod(float) +val floatModDouble = float.mod(double) +val doubleModFloat = double.mod(float) +val doubleModDouble = double.mod(double) diff --git a/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.txt b/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.txt new file mode 100644 index 00000000000..fc17fc133fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.txt @@ -0,0 +1,44 @@ +package + +public const val byte: kotlin.Byte = 1.toByte() +public val byteFloorByte: kotlin.Int = 1 +public val byteFloorInt: kotlin.Int = 0 +public val byteFloorLong: kotlin.Long = 0.toLong() +public val byteFloorShort: kotlin.Int = 0 +public val byteModByte: kotlin.Byte = 0.toByte() +public val byteModInt: kotlin.Int = 1 +public val byteModLong: kotlin.Long = 1.toLong() +public val byteModShort: kotlin.Short = 1.toShort() +public const val double: kotlin.Double = 6.0.toDouble() +public val doubleModDouble: kotlin.Double = 0.0.toDouble() +public val doubleModFloat: kotlin.Double = 1.0.toDouble() +public const val float: kotlin.Float = 5.0.toFloat() +public val floatModDouble: kotlin.Double = 5.0.toDouble() +public val floatModFloat: kotlin.Float = 0.0.toFloat() +public const val int: kotlin.Int = 3 +public val intFloorByte: kotlin.Int = 1 +public val intFloorInt: kotlin.Int = 0 +public val intFloorLong: kotlin.Long = 0.toLong() +public val intFloorShort: kotlin.Int = 0 +public val intModByte: kotlin.Byte = 0.toByte() +public val intModInt: kotlin.Int = 1 +public val intModLong: kotlin.Long = 1.toLong() +public val intModShort: kotlin.Short = 1.toShort() +public const val long: kotlin.Long = 4.toLong() +public val longFloorByte: kotlin.Int = 1 +public val longFloorInt: kotlin.Int = 0 +public val longFloorLong: kotlin.Long = 0.toLong() +public val longFloorShort: kotlin.Int = 0 +public val longModByte: kotlin.Byte = 0.toByte() +public val longModInt: kotlin.Int = 1 +public val longModLong: kotlin.Long = 1.toLong() +public val longModShort: kotlin.Short = 1.toShort() +public const val short: kotlin.Short = 2.toShort() +public val shortFloorByte: kotlin.Int = 1 +public val shortFloorInt: kotlin.Int = 0 +public val shortFloorLong: kotlin.Long = 0.toLong() +public val shortFloorShort: kotlin.Int = 0 +public val shortModByte: kotlin.Byte = 0.toByte() +public val shortModInt: kotlin.Int = 1 +public val shortModLong: kotlin.Long = 1.toLong() +public val shortModShort: kotlin.Short = 1.toShort() 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 91a8f488257..1e998d4bf2b 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 @@ -20063,6 +20063,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/modifiers/const/constInteraction.kt"); } + @Test + @TestMetadata("enumConstName.kt") + public void testEnumConstName() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/enumConstName.kt"); + } + @Test @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { @@ -20075,6 +20081,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.kt"); } + @Test + @TestMetadata("ifConstVal.kt") + public void testIfConstVal() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/ifConstVal.kt"); + } + + @Test + @TestMetadata("kCallable.kt") + public void testKCallable() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable.kt"); + } + @Test @TestMetadata("kt12248.kt") public void testKt12248() throws Exception { @@ -20087,6 +20105,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/modifiers/const/kt15913.kt"); } + @Test + @TestMetadata("stdlibConstFun.kt") + public void testStdlibConstFun() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/stdlibConstFun.kt"); + } + @Test @TestMetadata("types.kt") public void testTypes() throws Exception {