Do not recreate compile time initializer to avoid type info loosing

When we resolve arguments of annotation, expected type of parameters can
 be unknown. Therefore, if we'll try to load constants without expected type,
 info about unsigndness will be lost. For primitives it worked because we
 can differ type by its value
This commit is contained in:
Mikhail Zarechenskiy
2018-07-09 12:35:22 +03:00
parent 0c6757a8b0
commit 9b6e8fa5d1
3 changed files with 7 additions and 11 deletions
@@ -705,11 +705,7 @@ private class ConstantExpressionEvaluatorVisitor(
// TODO: FIXME: see KT-10425
if (callableDescriptor is PropertyDescriptor && callableDescriptor.modality != Modality.FINAL) return null
val variableInitializer = callableDescriptor.compileTimeInitializer ?: return null
return createConstant(
variableInitializer.value,
expectedType,
return callableDescriptor.compileTimeInitializer?.wrap(
CompileTimeConstant.Parameters(
canBeUsedInAnnotation = isPropertyCompileTimeConstant(callableDescriptor),
isPure = false,
@@ -8,10 +8,10 @@ public const val ui1: kotlin.UInt = 0.toUInt()
public const val ui2: kotlin.UInt = 42.toUInt()
public const val ul0: kotlin.ULong = 3.toULong()
public const val us0: kotlin.UShort = 2.toUShort()
@AnnoUB(ub0 = 1.toUByte(), ub1 = 1.toByte()) public fun f0(): kotlin.Unit
@AnnoUS(us0 = 7.toUShort(), us1 = 2.toShort()) public fun f1(): kotlin.Unit
@AnnoUI(ui0 = -1, ui1 = 0, ui2 = 42, ui3 = 100.toUInt()) public fun f2(): kotlin.Unit
@AnnoUL(ul0 = 3.toLong(), ul1 = 5.toULong()) public fun f3(): kotlin.Unit
@AnnoUB(ub0 = 1.toUByte(), ub1 = 1.toUByte()) public fun f0(): kotlin.Unit
@AnnoUS(us0 = 7.toUShort(), us1 = 2.toUShort()) public fun f1(): kotlin.Unit
@AnnoUI(ui0 = -1.toUInt(), ui1 = 0.toUInt(), ui2 = 42.toUInt(), ui3 = 100.toUInt()) public fun f2(): kotlin.Unit
@AnnoUL(ul0 = 3.toULong(), ul1 = 5.toULong()) public fun f3(): kotlin.Unit
public final annotation class AnnoUB : kotlin.Annotation {
public constructor AnnoUB(/*0*/ ub0: kotlin.UByte, /*1*/ ub1: kotlin.UByte)
@@ -13,5 +13,5 @@ public val m1: kotlin.UInt
public val n0: kotlin.Number = 1.toUInt()
public val u0: kotlin.UInt = 1.toUInt()
public val u1: kotlin.UInt? = 1.toUInt()
public val u2: kotlin.UInt? = 1
public val u3: kotlin.UInt? = 1
public val u2: kotlin.UInt? = 1.toUInt()
public val u3: kotlin.UInt? = 1.toUInt()