Enable signed to unsigned coercion for modules with special capability

Mainly this is needed for Kotlin/Native part
This commit is contained in:
Mikhail Zarechenskiy
2018-09-06 12:25:00 +03:00
parent 55ff519aa8
commit 5173a84dc7
2 changed files with 7 additions and 4 deletions
@@ -21,12 +21,15 @@ object ImplicitIntegerCoercion {
private fun isEnabledFor(descriptor: DeclarationDescriptor): Boolean =
descriptor.hasImplicitIntegerCoercionAnnotation() ||
DescriptorUtils.getContainingModuleOrNull(descriptor)
?.getCapability(ImplicitIntegerCoercion.MODULE_CAPABILITY) == true
DescriptorUtils.getContainingModuleOrNull(descriptor)?.hasImplicitIntegerCoercionCapability() == true
private val IMPLICIT_INTEGER_COERCION_ANNOTATION_FQ_NAME = FqName("kotlin.internal.ImplicitIntegerCoercion")
private fun DeclarationDescriptor.hasImplicitIntegerCoercionAnnotation(): Boolean {
return annotations.findAnnotation(IMPLICIT_INTEGER_COERCION_ANNOTATION_FQ_NAME) != null
}
}
}
fun ModuleDescriptor.hasImplicitIntegerCoercionCapability(): Boolean {
return getCapability(ImplicitIntegerCoercion.MODULE_CAPABILITY) == true
}
@@ -323,7 +323,7 @@ class CallCompleter(
val constant = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
val convertedConst = constant is IntegerValueTypeConstant && constant.convertedFromSigned
if (convertedConst) {
if (convertedConst && !moduleDescriptor.hasImplicitIntegerCoercionCapability()) {
context.trace.report(Errors.SIGNED_CONSTANT_CONVERTED_TO_UNSIGNED.on(deparenthesized))
}