From 5173a84dc73bb8bc032ea9441fb4cd8307e35209 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 6 Sep 2018 12:25:00 +0300 Subject: [PATCH] Enable signed to unsigned coercion for modules with special capability Mainly this is needed for Kotlin/Native part --- .../jetbrains/kotlin/resolve/ImplicitIntegerCoercion.kt | 9 ++++++--- .../org/jetbrains/kotlin/resolve/calls/CallCompleter.kt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImplicitIntegerCoercion.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImplicitIntegerCoercion.kt index 272cbf51bc0..af805ba8d75 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImplicitIntegerCoercion.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImplicitIntegerCoercion.kt @@ -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 } -} \ No newline at end of file +} + +fun ModuleDescriptor.hasImplicitIntegerCoercionCapability(): Boolean { + return getCapability(ImplicitIntegerCoercion.MODULE_CAPABILITY) == true +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index f3ba97846b6..bbb26989ec5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -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)) }