Report warning on usages of non-const vals in places where constants expected
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
// Properties can be recursively annotated
|
||||
annotation class ann(val x: Int)
|
||||
@ann(x) val x: Int = 1
|
||||
@ann(x) const val x: Int = 1
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
@ann(x = 1) public val x: kotlin.Int = 1
|
||||
@ann(x = 1) public const val x: kotlin.Int = 1
|
||||
|
||||
@kotlin.annotation.annotation() public final class ann : kotlin.Annotation {
|
||||
public constructor ann(/*0*/ x: kotlin.Int)
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ annotation class Ann(vararg val i: Int)
|
||||
class Test
|
||||
|
||||
var i1 = 1 // var
|
||||
val i2 = 1 // val
|
||||
const val i2 = 1 // val
|
||||
val i3 = i1 // val with var in initializer
|
||||
val i4 = i2 // val with val in initializer
|
||||
const val i4 = i2 // val with val in initializer
|
||||
var i5 = i1 // var with var in initializer
|
||||
var i6 = i2 // var with val in initializer
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package
|
||||
|
||||
public var i1: kotlin.Int
|
||||
public val i2: kotlin.Int = 1
|
||||
public const val i2: kotlin.Int = 1
|
||||
public val i3: kotlin.Int
|
||||
public val i4: kotlin.Int = 1
|
||||
public const val i4: kotlin.Int = 1
|
||||
public var i5: kotlin.Int
|
||||
public var i6: kotlin.Int
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
annotation class Ann(vararg val i: String)
|
||||
|
||||
val topLevel = "topLevel"
|
||||
const val topLevel = "topLevel"
|
||||
|
||||
fun foo() {
|
||||
val a1 = "a"
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public val topLevel: kotlin.String = "topLevel"
|
||||
public const val topLevel: kotlin.String = "topLevel"
|
||||
public fun foo(): kotlin.Unit
|
||||
|
||||
@kotlin.annotation.annotation() public final class Ann : kotlin.Annotation {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
annotation class ann(val name: String)
|
||||
val ok = "OK"
|
||||
const val ok = "OK"
|
||||
|
||||
class A
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package
|
||||
|
||||
public val extensionWithoutName: A.() -> kotlin.Unit
|
||||
public val funfun: () -> () -> kotlin.Int
|
||||
public val ok: kotlin.String = "OK"
|
||||
public const val ok: kotlin.String = "OK"
|
||||
public val parentesized: () -> kotlin.Unit
|
||||
public val parentesizedWithType: () -> kotlin.Unit
|
||||
public val withExpression: () -> kotlin.Int
|
||||
|
||||
compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.kt
Vendored
+1
-1
@@ -10,7 +10,7 @@ annotation class Ann(val i: IntArray)
|
||||
class Test
|
||||
|
||||
var i = 1
|
||||
val i2 = 1
|
||||
const val i2 = 1
|
||||
val i3 = foo()
|
||||
|
||||
fun foo(): Int = 1
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
public var i: kotlin.Int
|
||||
public val i2: kotlin.Int = 1
|
||||
public const val i2: kotlin.Int = 1
|
||||
public val i3: kotlin.Int
|
||||
public val iAnn: Ann
|
||||
public fun foo(): kotlin.Int
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
val nonConst = 1
|
||||
|
||||
const val constConst = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConst * nonConst + 2<!>
|
||||
|
||||
annotation class Ann(val x: Int, val y: String)
|
||||
|
||||
@Ann(<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConst<!>, <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>"${nonConst}"<!>)
|
||||
fun foo1() {}
|
||||
|
||||
@Ann(<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConst + constConst<!>, "${constConst}")
|
||||
fun foo2() {}
|
||||
|
||||
annotation class ArrayAnn(val x: IntArray)
|
||||
|
||||
@ArrayAnn(<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>intArrayOf(1, constConst, <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConst<!>)<!>)
|
||||
fun foo3() {}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package
|
||||
|
||||
public const val constConst: kotlin.Int = 3
|
||||
public val nonConst: kotlin.Int = 1
|
||||
@Ann(x = 1, y = "1") public fun foo1(): kotlin.Unit
|
||||
@Ann(x = 4, y = "3") public fun foo2(): kotlin.Unit
|
||||
@ArrayAnn(x = {1, 3, 1}) public fun foo3(): kotlin.Unit
|
||||
|
||||
@kotlin.annotation.annotation() public final class Ann : kotlin.Annotation {
|
||||
public constructor Ann(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String)
|
||||
public final val x: kotlin.Int
|
||||
public final val y: kotlin.String
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.annotation.annotation() public final class ArrayAnn : kotlin.Annotation {
|
||||
public constructor ArrayAnn(/*0*/ x: kotlin.IntArray)
|
||||
public final val x: kotlin.IntArray
|
||||
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
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ annotation class Ann(vararg val i: Int)
|
||||
class Test
|
||||
|
||||
var i = 1
|
||||
val i2 = 1
|
||||
const val i2 = 1
|
||||
val i3 = foo()
|
||||
|
||||
fun foo(): Int = 1
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
public var i: kotlin.Int
|
||||
public val i2: kotlin.Int = 1
|
||||
public const val i2: kotlin.Int = 1
|
||||
public val i3: kotlin.Int
|
||||
public val iAnn: Ann
|
||||
public fun foo(): kotlin.Int
|
||||
|
||||
Reference in New Issue
Block a user