Check expected type of annotation parameter correctly in AnnotationDeserializer
The main idea of this refactoring is to separate two usages of `AnnotationDeserializer.resolveValue`: the one where we load annotation argument values, and the one where we load constant values of properties for JS/Native/Common (`AnnotationAndConstantLoaderImpl.loadPropertyConstant`). In the latter case, `expectedType` is the type of the property and it can be a supertype of the actual value (e.g. see `arrayConst` in compiler/testData/serialization/builtinsSerializer/compileTimeConstants.kt). But in the former case, we need to check that the value conforms to the expected type and disregard it if it's not the case, which is possible if the annotation was recompiled separately. #KT-28927
This commit is contained in:
+2
-24
@@ -142,29 +142,7 @@ abstract class AbstractAnnotationDeserializer(
|
||||
)
|
||||
}
|
||||
// ARRAY -> {
|
||||
// val expectedIsArray = KotlinBuiltIns.isArray(expectedType) || KotlinBuiltIns.isPrimitiveArray(expectedType)
|
||||
// val arrayElements = value.arrayElementList
|
||||
//
|
||||
// val actualArrayType =
|
||||
// if (arrayElements.isNotEmpty()) {
|
||||
// val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver)
|
||||
// builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(actualElementType)
|
||||
// ?: builtIns.getArrayType(Variance.INVARIANT, actualElementType)
|
||||
// } else {
|
||||
// // In the case of empty array, no element has the element type, so we fall back to the expected type, if any.
|
||||
// // This is not very accurate when annotation class has been changed without recompiling clients,
|
||||
// // but should not in fact matter because the value is empty anyway
|
||||
// if (expectedIsArray) expectedType else builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType)
|
||||
// }
|
||||
//
|
||||
// val expectedElementType = builtIns.getArrayElementType(if (expectedIsArray) expectedType else actualArrayType)
|
||||
//
|
||||
// ConstantValueFactory.createArrayValue(
|
||||
// arrayElements.map {
|
||||
// resolveValue(expectedElementType, it, nameResolver)
|
||||
// },
|
||||
// actualArrayType
|
||||
// )
|
||||
// TODO: see AnnotationDeserializer
|
||||
// }
|
||||
// else -> error("Unsupported annotation argument type: ${value.type} (expected $expectedType)")
|
||||
else -> return null
|
||||
@@ -173,4 +151,4 @@ abstract class AbstractAnnotationDeserializer(
|
||||
}
|
||||
|
||||
private fun <T> const(kind: IrConstKind<T>, value: T) = FirConstExpressionImpl(session, null, kind, value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user