Make NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION error

This commit is contained in:
Zalim Bashorov
2015-10-16 15:07:31 +03:00
parent a16658a9e9
commit de5dc61820
33 changed files with 145 additions and 121 deletions
@@ -152,7 +152,7 @@ public interface Errors {
DiagnosticFactory0<PsiElement> CONST_VAL_WITHOUT_INITIALIZER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetExpression> CONST_VAL_WITH_NON_CONST_INITIALIZER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetExpression> NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetExpression> NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> INAPPLICABLE_TARGET_ON_PROPERTY = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> INAPPLICABLE_FIELD_TARGET_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
@@ -30,14 +30,14 @@ annotation class Ann(
class Foo {
companion object {
val i: Int = 2
val s: Short = 2
val f: Float = 2.0.toFloat()
val d: Double = 2.0
val l: Long = 2
val b: Byte = 2
val bool: Boolean = true
val c: Char = 'c'
val str: String = "str"
const val i: Int = 2
const val s: Short = 2
const val f: Float = 2.0.toFloat()
const val d: Double = 2.0
const val l: Long = 2
const val b: Byte = 2
const val bool: Boolean = true
const val c: Char = 'c'
const val str: String = "str"
}
}
@@ -28,12 +28,12 @@ annotation class Ann(
val str: String
)
val i: Int = 2
val s: Short = 2
val f: Float = 2.0.toFloat()
val d: Double = 2.0
val l: Long = 2
val b: Byte = 2
val bool: Boolean = true
val c: Char = 'c'
val str: String = "str"
const val i: Int = 2
const val s: Short = 2
const val f: Float = 2.0.toFloat()
const val d: Double = 2.0
const val l: Long = 2
const val b: Byte = 2
const val bool: Boolean = true
const val c: Char = 'c'
const val str: String = "str"
@@ -13,7 +13,7 @@ annotation class Ann(val i: Int)
class A {
class B {
companion object {
val i = 1
const val i = 1
}
}
}
@@ -10,5 +10,5 @@ fun box(): String {
@Retention(AnnotationRetention.RUNTIME)
annotation class Ann(val i: Int)
val i2: Int = 1
val i: Int = i2
const val i2: Int = 1
const val i: Int = i2
@@ -7,11 +7,11 @@ annotation class Ann(
val p5: Int
)
val prop1: Int = 1.plus(1)
val prop2: Int = 1.minus(1)
val prop3: Int = 1.times(1)
val prop4: Int = 1.div(1)
val prop5: Int = 1.mod(1)
const val prop1: Int = 1.plus(1)
const val prop2: Int = 1.minus(1)
const val prop3: Int = 1.times(1)
const val prop4: Int = 1.div(1)
const val prop5: Int = 1.mod(1)
@Ann(prop1, prop2, prop3, prop4, prop5) class MyClass
@@ -8,12 +8,12 @@ annotation class Ann(
val p6: Float
)
val prop1: Byte = -1
val prop2: Short = -1
val prop3: Int = -1
val prop4: Long = -1
val prop5: Double = -1.0
val prop6: Float = -1.0.toFloat()
const val prop1: Byte = -1
const val prop2: Short = -1
const val prop3: Int = -1
const val prop4: Long = -1
const val prop5: Double = -1.0
const val prop6: Float = -1.0.toFloat()
@Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
@@ -26,4 +26,4 @@ fun box(): String {
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
}
@@ -8,12 +8,12 @@ annotation class Ann(
val p6: Float
)
val prop1: Byte = +1
val prop2: Short = +1
val prop3: Int = +1
val prop4: Long = +1
val prop5: Double = +1.0
val prop6: Float = +1.0.toFloat()
const val prop1: Byte = +1
const val prop2: Short = +1
const val prop3: Int = +1
const val prop4: Long = +1
const val prop5: Double = +1.0
const val prop6: Float = +1.0.toFloat()
@Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
@@ -26,4 +26,4 @@ fun box(): String {
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
}
@@ -1,15 +1,15 @@
package constants
public val b: Byte = 100
public val s: Short = 20000
public val i: Int = 2000000
public val l: Long = 2000000000000L
public val f: Float = 3.14f
public val d: Double = 3.14
public val bb: Boolean = true
public val c: Char = '\u03c0' // pi symbol
public const val b: Byte = 100
public const val s: Short = 20000
public const val i: Int = 2000000
public const val l: Long = 2000000000000L
public const val f: Float = 3.14f
public const val d: Double = 3.14
public const val bb: Boolean = true
public const val c: Char = '\u03c0' // pi symbol
public val str: String = ":)"
public const val str: String = ":)"
@Retention(AnnotationRetention.RUNTIME)
public annotation class AnnotationClass(public val value: String)
public annotation class AnnotationClass(public val value: String)
@@ -1,21 +1,21 @@
package a
val i = 2
val s = 2.toShort()
val f = 2.0.toFloat()
val d = 2.0
val l = 2L
val b = 2.toByte()
val bool = true
val c = 'c'
val str = "str"
const val i = 2
const val s = 2.toShort()
const val f = 2.0.toFloat()
const val d = 2.0
const val l = 2L
const val b = 2.toByte()
const val bool = true
const val c = 'c'
const val str = "str"
val i2 = i
val s2 = s
val f2 = f
val d2 = d
val l2 = l
val b2 = b
val bool2 = bool
val c2 = c
val str2 = str
const val i2 = i
const val s2 = s
const val f2 = f
const val d2 = d
const val l2 = l
const val b2 = b
const val bool2 = bool
const val c2 = c
const val str2 = str
+2
View File
@@ -1,4 +1,6 @@
// "Add 'const' modifier" "true"
// ERROR: Only 'const val' can be used in constant expressions
package constVal
const val i = 1
@@ -1,4 +1,6 @@
// "Add 'const' modifier" "true"
// ERROR: Only 'const val' can be used in constant expressions
package constVal
val i = 1
@@ -87,6 +87,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
override fun getCompilableFileExtensions() = arrayListOf("kt")
override fun buildStarted(context: CompileContext) {
LOG.debug("==========================================")
LOG.info("is Kotlin incremental compilation enabled: ${IncrementalCompilation.isEnabled()}")
val historyLabel = context.getBuilderParameter("history label")
@@ -101,6 +102,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
outputConsumer: ModuleLevelBuilder.OutputConsumer
): ModuleLevelBuilder.ExitCode {
LOG.debug("------------------------------------------")
val messageCollector = MessageCollectorAdapter(context)
try {
@@ -213,7 +215,9 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
copyJsLibraryFilesIfNeeded(chunk, project)
}
if (!IncrementalCompilation.isEnabled()) return OK
if (!IncrementalCompilation.isEnabled()) {
return OK
}
val caches = filesToCompile.keySet().map { incrementalCaches[it]!! }
val marker = ChangesProcessor(context, chunk, allCompiledFiles, caches)
@@ -7,8 +7,16 @@ Compiling files:
module1/src/module1_const.kt
End of files
Cleaning output files:
out/production/module1/META-INF/module1.kotlin_module
out/production/module1/test/Module1_constKt.class
out/production/module1/test/TestPackage.class
End of files
Compiling files:
module1/src/module1_const.kt
End of files
Cleaning output files:
out/production/module2/usage/Usage.class
End of files
Compiling files:
module2/src/module2_usage.kt
End of files
End of files
@@ -1,3 +1,3 @@
package test
public val CONST: String = "BF"
public const val CONST: String = "BF"
@@ -1,3 +1,3 @@
package test
public val CONST: String = "Ae"
public const val CONST: String = "Ae"
@@ -17,8 +17,12 @@ Compiling files:
src/const.kt
End of files
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/ConstKt.class
out/production/module/test/TestPackage.class
out/production/module/test/Usage.class
End of files
Compiling files:
src/const.kt
src/usage.kt
End of files
End of files
@@ -1,12 +1,12 @@
package test
val b: Byte = 100
val s: Short = 20000
val i: Int = 2000000
val l: Long = 2000000000000L
val f: Float = 3.14f
val d: Double = 3.14
val bb: Boolean = true
val c: Char = '\u03c0' // pi symbol
const val b: Byte = 100
const val s: Short = 20000
const val i: Int = 2000000
const val l: Long = 2000000000000L
const val f: Float = 3.14f
const val d: Double = 3.14
const val bb: Boolean = true
const val c: Char = '\u03c0' // pi symbol
val str: String = ":)"
const val str: String = ":)"
@@ -1,12 +1,12 @@
package test
val b: Byte = 50 + 50
val s: Short = 10000 + 10000
val i: Int = 1000000 + 1000000
val l: Long = 1000000000000L + 1000000000000L
val f: Float = 0.0f + 3.14f
val d: Double = 0.0 + 3.14
val bb: Boolean = !false
val c: Char = '\u03c0' // pi symbol
const val b: Byte = 50 + 50
const val s: Short = 10000 + 10000
const val i: Int = 1000000 + 1000000
const val l: Long = 1000000000000L + 1000000000000L
const val f: Float = 0.0f + 3.14f
const val d: Double = 0.0 + 3.14
const val bb: Boolean = !false
const val c: Char = '\u03c0' // pi symbol
val str: String = ":)"
const val str: String = ":)"
@@ -1,12 +1,12 @@
package test
val b: Byte = 0
val s: Short = 0
val i: Int = 0
val l: Long = 0
val f: Float = 0.0f
val d: Double = 0.0
val bb: Boolean = false
val c: Char = 'x'
const val b: Byte = 0
const val s: Short = 0
const val i: Int = 0
const val l: Long = 0
const val f: Float = 0.0f
const val d: Double = 0.0
const val bb: Boolean = false
const val c: Char = 'x'
val str: String = ":("
const val str: String = ":("
@@ -3,6 +3,6 @@ package test
class Klass {
companion object {
// Old and new constant values are different, but their hashes are the same
val CONST = "BF"
const val CONST = "BF"
}
}
@@ -3,6 +3,6 @@ package test
class Klass {
companion object {
// Old and new constant values are different, but their hashes are the same
val CONST = "Ae"
const val CONST = "Ae"
}
}
@@ -1,9 +1,9 @@
package test
val CONST = "foo"
const val CONST = "foo"
class Klass {
companion object {
val CONST = "bar"
const val CONST = "bar"
}
}
@@ -1,9 +1,9 @@
package test
val CONST = "foo"
const val CONST = "foo"
class Klass {
companion object {
val CONST = "bar"
const val CONST = "bar"
}
}
@@ -1,3 +1,3 @@
package test
val CONST = "foo"
const val CONST = "foo"
@@ -1,5 +1,5 @@
package test
object Object {
val CONST = "old"
const val CONST = "old"
}
@@ -1,5 +1,5 @@
package test
object Object {
val CONST = "new"
const val CONST = "new"
}
@@ -7,8 +7,12 @@ Compiling files:
src/const.kt
End of files
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/ConstKt.class
out/production/module/test/TestPackage.class
out/production/module/test/Usage.class
End of files
Compiling files:
src/const.kt
src/usage.kt
End of files
End of files
@@ -1,4 +1,4 @@
package test
// Old and new constant values are different, but their hashes are the same
val CONST = "BF"
const val CONST = "BF"
@@ -1,4 +1,4 @@
package test
// Old and new constant values are different, but their hashes are the same
val CONST = "Ae"
const val CONST = "Ae"
@@ -1,11 +1,11 @@
package test
val CONST = "foo"
const val CONST = "foo"
class Klass {
companion object {
private val CHANGED = "old"
public val UNCHANGED = 100
const public val UNCHANGED = 100
}
}
@@ -1,11 +1,11 @@
package test
val CONST = "foo"
const val CONST = "foo"
class Klass {
companion object {
private val CHANGED = "new"
public val UNCHANGED = 100
const public val UNCHANGED = 100
}
}
@@ -3,11 +3,11 @@ package foo
// HACKS
@native
val ROOT = "Kotlin.modules.JS_TESTS"
const val ROOT = "Kotlin.modules.JS_TESTS"
@native
val PATH_TO_F_CREATOR = "foo.B.far\$f"
const val PATH_TO_F_CREATOR = "foo.B.far\$f"
@native
val PATH_TO_G_CREATOR = "foo.B.gar\$f"
const val PATH_TO_G_CREATOR = "foo.B.gar\$f"
@native("$ROOT.$PATH_TO_F_CREATOR")
val F_CREATOR: Any = noImpl
@@ -54,4 +54,4 @@ fun String.replace(regexp: RegExp, replacement: String): String = noImpl
fun String.replaceAll(regexp: String, replacement: String): String = replace(RegExp(regexp, "g"), replacement)
@native
class RegExp(regexp: String, flags: String)
class RegExp(regexp: String, flags: String)