K1: Place integer cinterop conversions under a language feature
Note that it's quite hard to emit a particular diagnostic as type check happens later, after the conversion ^KT-56583
This commit is contained in:
committed by
Space Team
parent
2cad26f4cc
commit
82524fde26
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -12,13 +14,10 @@ object ImplicitIntegerCoercion {
|
||||
|
||||
val MODULE_CAPABILITY = ModuleCapability<Boolean>("ImplicitIntegerCoercion")
|
||||
|
||||
fun isEnabledForParameter(descriptor: ParameterDescriptor): Boolean = isEnabledFor(descriptor)
|
||||
|
||||
fun isEnabledForConstVal(descriptor: VariableDescriptor): Boolean = isEnabledFor(descriptor)
|
||||
|
||||
private fun isEnabledFor(descriptor: DeclarationDescriptor): Boolean =
|
||||
fun isEnabledFor(descriptor: DeclarationDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean =
|
||||
descriptor.hasImplicitIntegerCoercionAnnotation() ||
|
||||
DescriptorUtils.getContainingModuleOrNull(descriptor)?.hasImplicitIntegerCoercionCapability() == true
|
||||
(languageVersionSettings.supportsFeature(LanguageFeature.ImplicitSignedToUnsignedIntegerConversion) &&
|
||||
DescriptorUtils.getContainingModuleOrNull(descriptor)?.hasImplicitIntegerCoercionCapability() == true)
|
||||
|
||||
private val IMPLICIT_INTEGER_COERCION_ANNOTATION_FQ_NAME = FqName("kotlin.internal.ImplicitIntegerCoercion")
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ class CallCompleter(
|
||||
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression) ?: updatedType
|
||||
}
|
||||
|
||||
if (parameter != null && ImplicitIntegerCoercion.isEnabledForParameter(parameter)) {
|
||||
if (parameter != null && ImplicitIntegerCoercion.isEnabledFor(parameter, context.languageVersionSettings)) {
|
||||
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
|
||||
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
||||
val generalNumberType = createTypeForConvertableConstant(argumentCompileTimeValue)
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.extensions.internal.CandidateInterceptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.ImplicitIntegerCoercion.isEnabledFor
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.DiagnosticReporterByTrackingStrategy
|
||||
@@ -370,7 +371,7 @@ class KotlinToResolvedCallTransformer(
|
||||
|
||||
var reportErrorDuringTypeCheck = reportErrorForTypeMismatch
|
||||
|
||||
if (parameter != null && ImplicitIntegerCoercion.isEnabledForParameter(parameter)) {
|
||||
if (parameter != null && isEnabledFor(parameter, context.languageVersionSettings)) {
|
||||
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
|
||||
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
||||
val generalNumberType = createTypeForConvertableConstant(argumentCompileTimeValue)
|
||||
|
||||
+1
-1
@@ -823,7 +823,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
|
||||
val isConvertableConstVal =
|
||||
callableDescriptor.isConst &&
|
||||
ImplicitIntegerCoercion.isEnabledForConstVal(callableDescriptor) &&
|
||||
ImplicitIntegerCoercion.isEnabledFor(callableDescriptor, languageVersionSettings) &&
|
||||
callableDescriptor.compileTimeInitializer is IntValue
|
||||
|
||||
return callableDescriptor.compileTimeInitializer?.wrap(
|
||||
|
||||
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||
// ALLOW_KOTLIN_PACKAGE
|
||||
|
||||
// FILE: annotation.kt
|
||||
|
||||
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||
// ALLOW_KOTLIN_PACKAGE
|
||||
|
||||
// FILE: annotation.kt
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// WITH_STDLIB
|
||||
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||
|
||||
// FILE: signedToUnsignedConversions_annotation.kt
|
||||
|
||||
|
||||
@@ -327,6 +327,7 @@ enum class LanguageFeature(
|
||||
InlineLateinit(sinceVersion = null, kind = OTHER), // KT-23814
|
||||
EnableDfaWarningsInK2(sinceVersion = null, kind = OTHER), // KT-50965
|
||||
ContractSyntaxV2(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-56127
|
||||
ImplicitSignedToUnsignedIntegerConversion(sinceVersion = null), // KT-56583
|
||||
;
|
||||
|
||||
init {
|
||||
|
||||
@@ -57,7 +57,8 @@ interface CompileTimeConstant<out T> {
|
||||
val isUnsignedLongNumberLiteral: Boolean,
|
||||
val usesVariableAsConstant: Boolean,
|
||||
val usesNonConstValAsConstant: Boolean,
|
||||
// `isConvertableConstVal` means that this is `const val` that has `ImplicitIntegerCoercion` annotation
|
||||
// `isConvertableConstVal` means that this is `const val` that can participate in signed to unsigned conversion
|
||||
// see LanguageFeature.ImplicitSignedToUnsignedIntegerConversion
|
||||
val isConvertableConstVal: Boolean
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user