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
|
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.descriptors.*
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
@@ -12,13 +14,10 @@ object ImplicitIntegerCoercion {
|
|||||||
|
|
||||||
val MODULE_CAPABILITY = ModuleCapability<Boolean>("ImplicitIntegerCoercion")
|
val MODULE_CAPABILITY = ModuleCapability<Boolean>("ImplicitIntegerCoercion")
|
||||||
|
|
||||||
fun isEnabledForParameter(descriptor: ParameterDescriptor): Boolean = isEnabledFor(descriptor)
|
fun isEnabledFor(descriptor: DeclarationDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean =
|
||||||
|
|
||||||
fun isEnabledForConstVal(descriptor: VariableDescriptor): Boolean = isEnabledFor(descriptor)
|
|
||||||
|
|
||||||
private fun isEnabledFor(descriptor: DeclarationDescriptor): Boolean =
|
|
||||||
descriptor.hasImplicitIntegerCoercionAnnotation() ||
|
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")
|
private val IMPLICIT_INTEGER_COERCION_ANNOTATION_FQ_NAME = FqName("kotlin.internal.ImplicitIntegerCoercion")
|
||||||
|
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ class CallCompleter(
|
|||||||
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression) ?: updatedType
|
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]
|
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
|
||||||
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
||||||
val generalNumberType = createTypeForConvertableConstant(argumentCompileTimeValue)
|
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.extensions.internal.CandidateInterceptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.*
|
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.ArgumentTypeResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||||
import org.jetbrains.kotlin.resolve.calls.DiagnosticReporterByTrackingStrategy
|
import org.jetbrains.kotlin.resolve.calls.DiagnosticReporterByTrackingStrategy
|
||||||
@@ -370,7 +371,7 @@ class KotlinToResolvedCallTransformer(
|
|||||||
|
|
||||||
var reportErrorDuringTypeCheck = reportErrorForTypeMismatch
|
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]
|
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
|
||||||
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
||||||
val generalNumberType = createTypeForConvertableConstant(argumentCompileTimeValue)
|
val generalNumberType = createTypeForConvertableConstant(argumentCompileTimeValue)
|
||||||
|
|||||||
+1
-1
@@ -823,7 +823,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
|||||||
|
|
||||||
val isConvertableConstVal =
|
val isConvertableConstVal =
|
||||||
callableDescriptor.isConst &&
|
callableDescriptor.isConst &&
|
||||||
ImplicitIntegerCoercion.isEnabledForConstVal(callableDescriptor) &&
|
ImplicitIntegerCoercion.isEnabledFor(callableDescriptor, languageVersionSettings) &&
|
||||||
callableDescriptor.compileTimeInitializer is IntValue
|
callableDescriptor.compileTimeInitializer is IntValue
|
||||||
|
|
||||||
return callableDescriptor.compileTimeInitializer?.wrap(
|
return callableDescriptor.compileTimeInitializer?.wrap(
|
||||||
|
|||||||
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||||
// ALLOW_KOTLIN_PACKAGE
|
// ALLOW_KOTLIN_PACKAGE
|
||||||
|
|
||||||
// FILE: annotation.kt
|
// FILE: annotation.kt
|
||||||
|
|||||||
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||||
// ALLOW_KOTLIN_PACKAGE
|
// ALLOW_KOTLIN_PACKAGE
|
||||||
|
|
||||||
// FILE: annotation.kt
|
// FILE: annotation.kt
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// IGNORE_BACKEND_K2: JVM_IR
|
// IGNORE_BACKEND_K2: JVM_IR
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
|
||||||
|
|
||||||
// FILE: signedToUnsignedConversions_annotation.kt
|
// FILE: signedToUnsignedConversions_annotation.kt
|
||||||
|
|
||||||
|
|||||||
@@ -327,6 +327,7 @@ enum class LanguageFeature(
|
|||||||
InlineLateinit(sinceVersion = null, kind = OTHER), // KT-23814
|
InlineLateinit(sinceVersion = null, kind = OTHER), // KT-23814
|
||||||
EnableDfaWarningsInK2(sinceVersion = null, kind = OTHER), // KT-50965
|
EnableDfaWarningsInK2(sinceVersion = null, kind = OTHER), // KT-50965
|
||||||
ContractSyntaxV2(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-56127
|
ContractSyntaxV2(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-56127
|
||||||
|
ImplicitSignedToUnsignedIntegerConversion(sinceVersion = null), // KT-56583
|
||||||
;
|
;
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ interface CompileTimeConstant<out T> {
|
|||||||
val isUnsignedLongNumberLiteral: Boolean,
|
val isUnsignedLongNumberLiteral: Boolean,
|
||||||
val usesVariableAsConstant: Boolean,
|
val usesVariableAsConstant: Boolean,
|
||||||
val usesNonConstValAsConstant: 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
|
val isConvertableConstVal: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user