[FE] Drop ApproximateIntegerLiteralTypesInReceiverPosition language feature

This feature is not needed because it is unconditionally disabled for K1
  (because of not fully correct implementation) and unconditionally enabled
  in K2 (K2 does not support old behavior)

^KT-38895
This commit is contained in:
Dmitriy Novozhilov
2022-11-30 12:22:09 +02:00
committed by Space Team
parent 26ff806440
commit 3cffb33ab7
90 changed files with 90 additions and 494 deletions
@@ -22285,15 +22285,9 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
} }
@Test @Test
@TestMetadata("kt48361_disabled.kt") @TestMetadata("kt48361.kt")
public void testKt48361_disabled() throws Exception { public void testKt48361() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); runTest("compiler/testData/diagnostics/tests/numbers/kt48361.kt");
}
@Test
@TestMetadata("kt48361_enabled.kt")
public void testKt48361_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt");
} }
@Test @Test
@@ -22302,12 +22296,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt"); runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt");
} }
@Test
@TestMetadata("newLiteralOperatorsResolution_newResolve.kt")
public void testNewLiteralOperatorsResolution_newResolve() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.kt");
}
@Test @Test
@TestMetadata("newLiteralOperatorsResolution_warning.kt") @TestMetadata("newLiteralOperatorsResolution_warning.kt")
public void testNewLiteralOperatorsResolution_warning() throws Exception { public void testNewLiteralOperatorsResolution_warning() throws Exception {
@@ -22291,15 +22291,9 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
} }
@Test @Test
@TestMetadata("kt48361_disabled.kt") @TestMetadata("kt48361.kt")
public void testKt48361_disabled() throws Exception { public void testKt48361() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); runTest("compiler/testData/diagnostics/tests/numbers/kt48361.kt");
}
@Test
@TestMetadata("kt48361_enabled.kt")
public void testKt48361_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt");
} }
@Test @Test
@@ -22308,12 +22302,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt"); runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt");
} }
@Test
@TestMetadata("newLiteralOperatorsResolution_newResolve.kt")
public void testNewLiteralOperatorsResolution_newResolve() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.kt");
}
@Test @Test
@TestMetadata("newLiteralOperatorsResolution_warning.kt") @TestMetadata("newLiteralOperatorsResolution_warning.kt")
public void testNewLiteralOperatorsResolution_warning() throws Exception { public void testNewLiteralOperatorsResolution_warning() throws Exception {
@@ -22285,15 +22285,9 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
} }
@Test @Test
@TestMetadata("kt48361_disabled.kt") @TestMetadata("kt48361.kt")
public void testKt48361_disabled() throws Exception { public void testKt48361() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); runTest("compiler/testData/diagnostics/tests/numbers/kt48361.kt");
}
@Test
@TestMetadata("kt48361_enabled.kt")
public void testKt48361_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt");
} }
@Test @Test
@@ -22302,12 +22296,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt"); runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt");
} }
@Test
@TestMetadata("newLiteralOperatorsResolution_newResolve.kt")
public void testNewLiteralOperatorsResolution_newResolve() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.kt");
}
@Test @Test
@TestMetadata("newLiteralOperatorsResolution_warning.kt") @TestMetadata("newLiteralOperatorsResolution_warning.kt")
public void testNewLiteralOperatorsResolution_warning() throws Exception { public void testNewLiteralOperatorsResolution_warning() throws Exception {
@@ -131,7 +131,6 @@ class VariableTypeAndInitializerResolver(
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument( NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(
variableType, variableType,
initializer, initializer,
languageVersionSettings,
trace, trace,
constantExpressionEvaluator.module constantExpressionEvaluator.module
) )
@@ -6,11 +6,8 @@
package org.jetbrains.kotlin.resolve.calls.checkers package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -33,7 +30,6 @@ import org.jetbrains.kotlin.types.typeUtil.*
object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition)) return
for ((valueParameter, arguments) in resolvedCall.valueArguments) { for ((valueParameter, arguments) in resolvedCall.valueArguments) {
val expectedType = if (valueParameter.isVararg) { val expectedType = if (valueParameter.isVararg) {
valueParameter.varargElementType ?: continue valueParameter.varargElementType ?: continue
@@ -54,11 +50,9 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker {
fun checkArgument( fun checkArgument(
expectedType: KotlinType, expectedType: KotlinType,
argument: KtExpression, argument: KtExpression,
languageVersionSettings: LanguageVersionSettings,
trace: BindingTrace, trace: BindingTrace,
moduleDescriptor: ModuleDescriptor moduleDescriptor: ModuleDescriptor
) { ) {
if (languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition)) return
val type = expectedType.lowerIfFlexible() val type = expectedType.lowerIfFlexible()
if (type.isPrimitiveNumberOrNullableType()) { if (type.isPrimitiveNumberOrNullableType()) {
checkArgumentImpl(type, KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor) checkArgumentImpl(type, KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor)
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.builtins.UnsignedTypes
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
@@ -286,10 +285,9 @@ class ConstantExpressionEvaluator(
fun evaluateExpression( fun evaluateExpression(
expression: KtExpression, expression: KtExpression,
trace: BindingTrace, trace: BindingTrace,
expectedType: KotlinType? = TypeUtils.NO_EXPECTED_TYPE, expectedType: KotlinType? = TypeUtils.NO_EXPECTED_TYPE
isIndependentContext: Boolean = false
): CompileTimeConstant<*>? { ): CompileTimeConstant<*>? {
val visitor = ConstantExpressionEvaluatorVisitor(this, trace, isIndependentContext) val visitor = ConstantExpressionEvaluatorVisitor(this, trace)
val constant = visitor.evaluate(expression, expectedType) ?: return null val constant = visitor.evaluate(expression, expectedType) ?: return null
checkExperimentalityOfConstantLiteral(expression, constant, expectedType, trace) checkExperimentalityOfConstantLiteral(expression, constant, expectedType, trace)
@@ -389,13 +387,10 @@ private val DIVISION_OPERATION_NAMES =
private class ConstantExpressionEvaluatorVisitor( private class ConstantExpressionEvaluatorVisitor(
private val constantExpressionEvaluator: ConstantExpressionEvaluator, private val constantExpressionEvaluator: ConstantExpressionEvaluator,
private val trace: BindingTrace, private val trace: BindingTrace
private val isIndependentContext: Boolean
) : KtVisitor<CompileTimeConstant<*>?, KotlinType>() { ) : KtVisitor<CompileTimeConstant<*>?, KotlinType>() {
private val languageVersionSettings = constantExpressionEvaluator.languageVersionSettings private val languageVersionSettings = constantExpressionEvaluator.languageVersionSettings
private val builtIns = constantExpressionEvaluator.module.builtIns private val builtIns = constantExpressionEvaluator.module.builtIns
private val defaultValueForDontCreateIntegerLiteralType =
languageVersionSettings.supportsFeature(ApproximateIntegerLiteralTypesInReceiverPosition)
private val inlineConstTracker = private val inlineConstTracker =
if (constantExpressionEvaluator.inlineConstTracker is InlineConstTracker.DoNothing) if (constantExpressionEvaluator.inlineConstTracker is InlineConstTracker.DoNothing)
null null
@@ -530,8 +525,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLongNumberLiteral = isUnsignedLong, isUnsignedLongNumberLiteral = isUnsignedLong,
usesVariableAsConstant = false, usesVariableAsConstant = false,
usesNonConstValAsConstant = false, usesNonConstValAsConstant = false,
isConvertableConstVal = false, isConvertableConstVal = false
dontCreateILT = defaultValueForDontCreateIntegerLiteralType && isIndependentContext
) )
) )
} }
@@ -581,8 +575,7 @@ private class ConstantExpressionEvaluatorVisitor(
canBeUsedInAnnotation = canBeUsedInAnnotation, canBeUsedInAnnotation = canBeUsedInAnnotation,
usesVariableAsConstant = usesVariableAsConstant, usesVariableAsConstant = usesVariableAsConstant,
usesNonConstValAsConstant = usesNonConstantVariableAsConstant, usesNonConstValAsConstant = usesNonConstantVariableAsConstant,
isConvertableConstVal = false, isConvertableConstVal = false
dontCreateILT = false
) )
) )
else null else null
@@ -646,8 +639,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLongNumberLiteral = false, isUnsignedLongNumberLiteral = false,
usesVariableAsConstant = leftConstant.usesVariableAsConstant || rightConstant.usesVariableAsConstant, usesVariableAsConstant = leftConstant.usesVariableAsConstant || rightConstant.usesVariableAsConstant,
usesNonConstValAsConstant = leftConstant.usesNonConstValAsConstant || rightConstant.usesNonConstValAsConstant, usesNonConstValAsConstant = leftConstant.usesNonConstValAsConstant || rightConstant.usesNonConstValAsConstant,
isConvertableConstVal = false, isConvertableConstVal = false
dontCreateILT = false
) )
) )
} else { } else {
@@ -666,8 +658,7 @@ private class ConstantExpressionEvaluatorVisitor(
private fun evaluateCall( private fun evaluateCall(
callExpression: KtExpression, callExpression: KtExpression,
receiverExpression: KtExpression, receiverExpression: KtExpression,
expectedType: KotlinType?, expectedType: KotlinType?
isUnaryPlusMinus: Boolean = false
): CompileTimeConstant<*>? { ): CompileTimeConstant<*>? {
val resolvedCall = callExpression.getResolvedCall(trace.bindingContext) ?: return null val resolvedCall = callExpression.getResolvedCall(trace.bindingContext) ?: return null
if (!KotlinBuiltIns.isUnderKotlinPackage(resolvedCall.resultingDescriptor)) return null if (!KotlinBuiltIns.isUnderKotlinPackage(resolvedCall.resultingDescriptor)) return null
@@ -689,12 +680,9 @@ private class ConstantExpressionEvaluatorVisitor(
val usesNonConstValAsConstant = usesNonConstValAsConstant(argumentForReceiver.expression) val usesNonConstValAsConstant = usesNonConstValAsConstant(argumentForReceiver.expression)
val isNumberConversionMethod = resultingDescriptorName in OperatorConventions.NUMBER_CONVERSIONS val isNumberConversionMethod = resultingDescriptorName in OperatorConventions.NUMBER_CONVERSIONS
val isCharCode = argumentForReceiver.ctcType == CHAR && resultingDescriptorName == StandardNames.CHAR_CODE val isCharCode = argumentForReceiver.ctcType == CHAR && resultingDescriptorName == StandardNames.CHAR_CODE
val dontCreateILT = defaultValueForDontCreateIntegerLiteralType &&
!isUnaryPlusMinus &&
!hasIntegerLiteralType(receiverExpression)
return createConstant( return createConstant(
result, result,
expectedType.takeUnless { dontCreateILT }, expectedType,
CompileTimeConstant.Parameters( CompileTimeConstant.Parameters(
canBeUsedInAnnotation, canBeUsedInAnnotation,
!isNumberConversionMethod && !isCharCode && isArgumentPure, !isNumberConversionMethod && !isCharCode && isArgumentPure,
@@ -702,8 +690,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLongNumberLiteral = false, isUnsignedLongNumberLiteral = false,
usesVariableAsConstant, usesVariableAsConstant,
usesNonConstValAsConstant, usesNonConstValAsConstant,
isConvertableConstVal = false, isConvertableConstVal = false
dontCreateILT = dontCreateILT
) )
) )
} else if (argumentsEntrySet.size == 1) { } else if (argumentsEntrySet.size == 1) {
@@ -738,7 +725,6 @@ private class ConstantExpressionEvaluatorVisitor(
usesVariableAsConstant(argumentForReceiver.expression) || usesVariableAsConstant(argumentForParameter.expression) usesVariableAsConstant(argumentForReceiver.expression) || usesVariableAsConstant(argumentForParameter.expression)
val usesNonConstValAsConstant = val usesNonConstValAsConstant =
usesNonConstValAsConstant(argumentForReceiver.expression) || usesNonConstValAsConstant(argumentForParameter.expression) usesNonConstValAsConstant(argumentForReceiver.expression) || usesNonConstValAsConstant(argumentForParameter.expression)
val dontCreateILT = defaultValueForDontCreateIntegerLiteralType && !hasIntegerLiteralType(receiverExpression)
val parameters = CompileTimeConstant.Parameters( val parameters = CompileTimeConstant.Parameters(
canBeUsedInAnnotation, canBeUsedInAnnotation,
areArgumentsPure, areArgumentsPure,
@@ -746,8 +732,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLongNumberLiteral = false, isUnsignedLongNumberLiteral = false,
usesVariableAsConstant, usesVariableAsConstant,
usesNonConstValAsConstant, usesNonConstValAsConstant,
isConvertableConstVal = false, isConvertableConstVal = false
dontCreateILT = dontCreateILT
) )
return when (resultingDescriptorName) { return when (resultingDescriptorName) {
OperatorNameConventions.COMPARE_TO -> createCompileTimeConstantForCompareTo(result, callExpression)?.wrap(parameters) OperatorNameConventions.COMPARE_TO -> createCompileTimeConstantForCompareTo(result, callExpression)?.wrap(parameters)
@@ -755,7 +740,7 @@ private class ConstantExpressionEvaluatorVisitor(
else -> { else -> {
createConstant( createConstant(
result, result,
expectedType.takeUnless { dontCreateILT }, expectedType,
parameters parameters
) )
} }
@@ -777,9 +762,6 @@ private class ConstantExpressionEvaluatorVisitor(
private fun isPureConstant(expression: KtExpression) = private fun isPureConstant(expression: KtExpression) =
ConstantExpressionEvaluator.getConstant(expression, trace.bindingContext)?.isPure ?: false ConstantExpressionEvaluator.getConstant(expression, trace.bindingContext)?.isPure ?: false
private fun hasIntegerLiteralType(expression: KtExpression): Boolean =
ConstantExpressionEvaluator.getConstant(expression, trace.bindingContext)?.hasIntegerLiteralType ?: false
private fun evaluateUnaryAndCheck(receiver: OperationArgument, name: String, callExpression: KtExpression): Any? { private fun evaluateUnaryAndCheck(receiver: OperationArgument, name: String, callExpression: KtExpression): Any? {
return evaluateUnaryAndCheck(name, receiver.ctcType, receiver.value) { return evaluateUnaryAndCheck(name, receiver.ctcType, receiver.value) {
trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType() ?: callExpression)) trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType() ?: callExpression))
@@ -803,12 +785,10 @@ private class ConstantExpressionEvaluatorVisitor(
override fun visitUnaryExpression(expression: KtUnaryExpression, expectedType: KotlinType?): CompileTimeConstant<*>? { override fun visitUnaryExpression(expression: KtUnaryExpression, expectedType: KotlinType?): CompileTimeConstant<*>? {
val leftExpression = expression.baseExpression ?: return null val leftExpression = expression.baseExpression ?: return null
val tokenType = expression.operationToken
return evaluateCall( return evaluateCall(
expression.operationReference, expression.operationReference,
leftExpression, leftExpression,
expectedType, expectedType
isUnaryPlusMinus = tokenType == KtTokens.PLUS || tokenType == KtTokens.MINUS
) )
} }
@@ -847,8 +827,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLongNumberLiteral = false, isUnsignedLongNumberLiteral = false,
usesVariableAsConstant = true, usesVariableAsConstant = true,
usesNonConstValAsConstant = !callableDescriptor.isConst, usesNonConstValAsConstant = !callableDescriptor.isConst,
isConvertableConstVal = isConvertableConstVal, isConvertableConstVal = isConvertableConstVal
dontCreateILT = true
) )
) )
} }
@@ -1108,9 +1087,7 @@ private class ConstantExpressionEvaluatorVisitor(
} }
if (TypeUtils.noExpectedType(expectedType) || expectedType.isError) { if (TypeUtils.noExpectedType(expectedType) || expectedType.isError) {
return if (parameters.dontCreateILT) { return createIntegerValueTypeConstant(
value.createSimpleIntCompileTimeConst(parameters)
} else createIntegerValueTypeConstant(
value, value,
constantExpressionEvaluator.module, constantExpressionEvaluator.module,
parameters, parameters,
@@ -1159,8 +1136,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLong: Boolean = false, isUnsignedLong: Boolean = false,
usesVariableAsConstant: Boolean = false, usesVariableAsConstant: Boolean = false,
usesNonConstValAsConstant: Boolean = false, usesNonConstValAsConstant: Boolean = false,
isConvertableConstVal: Boolean = false, isConvertableConstVal: Boolean = false
dontCreateILT: Boolean = false
): TypedCompileTimeConstant<T> = ): TypedCompileTimeConstant<T> =
wrap( wrap(
CompileTimeConstant.Parameters( CompileTimeConstant.Parameters(
@@ -1170,8 +1146,7 @@ private class ConstantExpressionEvaluatorVisitor(
isUnsignedLong, isUnsignedLong,
usesVariableAsConstant, usesVariableAsConstant,
usesNonConstValAsConstant, usesNonConstValAsConstant,
isConvertableConstVal, isConvertableConstVal
dontCreateILT
) )
) )
} }
@@ -181,7 +181,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
checkNull(expression, context, typeInfo.getType()); checkNull(expression, context, typeInfo.getType());
components.constantExpressionEvaluator.evaluateExpression( components.constantExpressionEvaluator.evaluateExpression(
expression, context.trace, context.expectedType, evaluateIntegerConstantInIndependentMode(context) expression, context.trace, context.expectedType
); );
return components.dataFlowAnalyzer.checkType(typeInfo, expression, context); // TODO : Extensions to this return components.dataFlowAnalyzer.checkType(typeInfo, expression, context); // TODO : Extensions to this
} }
@@ -217,7 +217,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
CompileTimeConstant<?> compileTimeConstant = components.constantExpressionEvaluator.evaluateExpression( CompileTimeConstant<?> compileTimeConstant = components.constantExpressionEvaluator.evaluateExpression(
expression, context.trace, context.expectedType, evaluateIntegerConstantInIndependentMode(context) expression, context.trace, context.expectedType
); );
if (compileTimeConstant instanceof UnsignedErrorValueTypeConstant) { if (compileTimeConstant instanceof UnsignedErrorValueTypeConstant) {
@@ -830,7 +830,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
CompileTimeConstant<?> value = components.constantExpressionEvaluator.evaluateExpression( CompileTimeConstant<?> value = components.constantExpressionEvaluator.evaluateExpression(
expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType, evaluateIntegerConstantInIndependentMode(context) expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType
); );
if (value != null) { if (value != null) {
return components.dataFlowAnalyzer.createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType); return components.dataFlowAnalyzer.createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
@@ -1126,7 +1126,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
result = TypeInfoFactoryKt.noTypeInfo(context); result = TypeInfoFactoryKt.noTypeInfo(context);
} }
CompileTimeConstant<?> value = components.constantExpressionEvaluator.evaluateExpression( CompileTimeConstant<?> value = components.constantExpressionEvaluator.evaluateExpression(
expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType, evaluateIntegerConstantInIndependentMode(context) expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType
); );
if (value != null) { if (value != null) {
return components.dataFlowAnalyzer.createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType); return components.dataFlowAnalyzer.createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
@@ -1602,7 +1602,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
for (KtStringTemplateEntry entry : expression.getEntries()) { for (KtStringTemplateEntry entry : expression.getEntries()) {
entry.accept(visitor); entry.accept(visitor);
} }
components.constantExpressionEvaluator.evaluateExpression(expression, context.trace, contextWithExpectedType.expectedType, evaluateIntegerConstantInIndependentMode(context)); components.constantExpressionEvaluator.evaluateExpression(expression, context.trace, contextWithExpectedType.expectedType);
return components.dataFlowAnalyzer.checkType(visitor.typeInfo.replaceType(components.builtIns.getStringType()), return components.dataFlowAnalyzer.checkType(visitor.typeInfo.replaceType(components.builtIns.getStringType()),
expression, expression,
contextWithExpectedType); contextWithExpectedType);
@@ -1805,8 +1805,4 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext()); return BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
} }
} }
private boolean evaluateIntegerConstantInIndependentMode(ExpressionTypingContext context) {
return context.contextDependency == INDEPENDENT && context.languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition);
}
} }
@@ -474,7 +474,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
DataFlowValue rightValue = components.dataFlowValueFactory.createDataFlowValue(right, rightType, context); DataFlowValue rightValue = components.dataFlowValueFactory.createDataFlowValue(right, rightType, context);
// We cannot say here anything new about rightValue except it has the same value as leftValue // We cannot say here anything new about rightValue except it has the same value as leftValue
resultInfo = resultInfo.replaceDataFlowInfo(dataFlowInfo.assign(leftValue, rightValue, components.languageVersionSettings)); resultInfo = resultInfo.replaceDataFlowInfo(dataFlowInfo.assign(leftValue, rightValue, components.languageVersionSettings));
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(expectedType, right, context.languageVersionSettings, context.trace, components.moduleDescriptor); NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(expectedType, right, context.trace, components.moduleDescriptor);
} }
} }
else { else {
@@ -75,7 +75,6 @@ class ValueParameterResolver(
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument( NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(
type, type,
defaultValue, defaultValue,
context.languageVersionSettings,
context.trace, context.trace,
constantExpressionEvaluator.module constantExpressionEvaluator.module
) )
@@ -1,4 +1,4 @@
$TESTDATA_DIR$/overridingXx.kt $TESTDATA_DIR$/overridingXx.kt
-d -d
$TEMP_DIR$ $TEMP_DIR$
-XXLanguage\:+ApproximateIntegerLiteralTypesInReceiverPosition -XXLanguage\:+RangeUntilOperator
@@ -1 +1 @@
-XXLanguage:-ApproximateIntegerLiteralTypesInReceiverPosition -XXLanguage:-RangeUntilOperator
@@ -1,3 +1,7 @@
fun foo(ttlMillis: Long = 5 * 60 * 1000) {} fun test(): Int {
var res = 0
const val cacheSize: Long = 4096 * 4 for (x in 100 ..< 1) {
res += x
}
return res
}
@@ -1,13 +1,16 @@
warning: ATTENTION! warning: ATTENTION!
This build uses unsafe internal compiler arguments: This build uses unsafe internal compiler arguments:
-XXLanguage:-ApproximateIntegerLiteralTypesInReceiverPosition -XXLanguage:-RangeUntilOperator
This mode is not recommended for production use, This mode is not recommended for production use,
as no stability/compatibility guarantees are given on as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk! compiler or generated code. Use it at your own risk!
compiler/testData/cli/jvm/readingConfigFromEnvironment/overridingXx.kt:1:9: warning: parameter 'ttlMillis' is never used compiler/testData/cli/jvm/readingConfigFromEnvironment/overridingXx.kt:3:19: error: this declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
fun foo(ttlMillis: Long = 5 * 60 * 1000) {} for (x in 100 ..< 1) {
^ ^
OK compiler/testData/cli/jvm/readingConfigFromEnvironment/overridingXx.kt:3:19: error: the feature "range until operator" is disabled
for (x in 100 ..< 1) {
^
COMPILATION_ERROR
@@ -1,7 +1,6 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// WITH_STDLIB // WITH_STDLIB
// This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321). // This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321).
// Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895). // Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895).
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte = 1.plus(1) val a1: Byte = 1.plus(1)
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte? = 1.plus(1) val a1: Byte? = 1.plus(1)
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte = 1 + 1 val a1: Byte = 1 + 1
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte? = 1 + 1 val a1: Byte? = 1 + 1
@@ -1,5 +1,3 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun box(): String { fun box(): String {
val a: Long = 2147483647 + 1 val a: Long = 2147483647 + 1
if (a != -2147483648L) return "fail: in this case we should add to ints and than cast the result to long - overflow expected" if (a != -2147483648L) return "fail: in this case we should add to ints and than cast the result to long - overflow expected"
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_FIR_DIAGNOSTICS // IGNORE_FIR_DIAGNOSTICS
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_FIR_DIAGNOSTICS // IGNORE_FIR_DIAGNOSTICS
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -2
View File
@@ -1,6 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_FIR_DIAGNOSTICS // IGNORE_FIR_DIAGNOSTICS
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
-1
View File
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_FIR_DIAGNOSTICS // IGNORE_FIR_DIAGNOSTICS
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_STDLIB // WITH_STDLIB
+1 -2
View File
@@ -1,7 +1,6 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// SKIP_JDK6 // SKIP_JDK6
// FULL_JDK // FULL_JDK
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte = 1.unaryMinus() val a1: Byte = 1.unaryMinus()
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR, JS_IR // IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
fun box(): String { fun box(): String {
val a1: Byte? = 1.unaryMinus() val a1: Byte? = 1.unaryMinus()
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_REFLECT // WITH_REFLECT
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
@@ -65,4 +64,4 @@ fun box(): String {
} }
return "OK" return "OK"
} }
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_REFLECT // WITH_REFLECT
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
@@ -62,4 +61,4 @@ fun box(): String {
} }
return "OK" return "OK"
} }
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR // IGNORE_BACKEND_K2: JVM_IR
// For reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
val a: Byte = 1 + 10 val a: Byte = 1 + 10
+1 -2
View File
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR // IGNORE_BACKEND_K2: JVM_IR
// For reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
val a: Short = 1 + 255 val a: Short = 1 + 255
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann(<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>p1: Int<!>, annotation class Ann(<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>p1: Int<!>,
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann(<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>p1: Int<!>, annotation class Ann(<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>p1: Int<!>,
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
package test package test
annotation class Ann( annotation class Ann(
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,4 @@
// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses -ApproximateIntegerLiteralTypesInReceiverPosition // !LANGUAGE: +InlineClasses, -JvmInlineValueClasses
// SKIP_JAVAC // SKIP_JAVAC
// ALLOW_KOTLIN_PACKAGE // ALLOW_KOTLIN_PACKAGE
@@ -1,4 +1,4 @@
// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses -ApproximateIntegerLiteralTypesInReceiverPosition // !LANGUAGE: +InlineClasses, -JvmInlineValueClasses
// SKIP_JAVAC // SKIP_JAVAC
// ALLOW_KOTLIN_PACKAGE // ALLOW_KOTLIN_PACKAGE
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun fooInt(p: Int) = p fun fooInt(p: Int) = p
fun fooLong(p: Long) = p fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p fun fooByte(p: Byte) = p
@@ -1,4 +1,3 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition
val p1: Byte = <!TYPE_MISMATCH!>(1 + 2) * 2<!> val p1: Byte = <!TYPE_MISMATCH!>(1 + 2) * 2<!>
val p2: Short = <!TYPE_MISMATCH!>(1 + 2) * 2<!> val p2: Short = <!TYPE_MISMATCH!>(1 + 2) * 2<!>
val p3: Int = (1 + 2) * 2 val p3: Int = (1 + 2) * 2
@@ -1,11 +1,10 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition val p1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>(1 + 2) * 2<!>
val p1: Byte = <!TYPE_MISMATCH!>(1 + 2) * 2<!> val p2: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>(1 + 2) * 2<!>
val p2: Short = <!TYPE_MISMATCH!>(1 + 2) * 2<!>
val p3: Int = (1 + 2) * 2 val p3: Int = (1 + 2) * 2
val p4: Long = <!TYPE_MISMATCH!>(1 + 2) * 2<!> val p4: Long = (1 + 2) * 2
val b1: Byte = <!TYPE_MISMATCH!>(1.toByte() + 2) * 2<!> val b1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>(1.toByte() + 2) * 2<!>
val b2: Short = <!TYPE_MISMATCH!>(1.toShort() + 2) * 2<!> val b2: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>(1.toShort() + 2) * 2<!>
val b3: Int = (1.toInt() + 2) * 2 val b3: Int = (1.toInt() + 2) * 2
val b4: Long = (1.toLong() + 2) * 2 val b4: Long = (1.toLong() + 2) * 2
@@ -6,8 +6,8 @@ public val b3: kotlin.Int = 6
public val b4: kotlin.Long = 6.toLong() public val b4: kotlin.Long = 6.toLong()
public val i1: kotlin.Int = 6 public val i1: kotlin.Int = 6
public val i2: kotlin.Int = 6 public val i2: kotlin.Int = 6
public val p1: kotlin.Byte = 6 public val p1: kotlin.Byte = 6.toByte()
public val p2: kotlin.Short = 6 public val p2: kotlin.Short = 6.toShort()
public val p3: kotlin.Int = 6 public val p3: kotlin.Int = 6
public val p4: kotlin.Long = 6 public val p4: kotlin.Long = 6.toLong()
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// ISSUE: KT-47447 // ISSUE: KT-47447
// FULL_JDK // FULL_JDK
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// ISSUE: Kt-47447, KT-47729 // ISSUE: Kt-47447, KT-47729
fun takeLong(value : Long) {} fun takeLong(value : Long) {}
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// ISSUE: Kt-47447, KT-47729 // ISSUE: Kt-47447, KT-47729
fun takeLong(x: Long) {} fun takeLong(x: Long) {}
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
fun foo(ttlMillis: Long = 5 * 60 * 1000) {} fun foo(ttlMillis: Long = 5 * 60 * 1000) {}
@@ -1,6 +0,0 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition
fun foo(ttlMillis: Long = 5 * 60 * 1000) {}
const val cacheSize: Long = 4096 * 4
@@ -1,6 +0,0 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition
fun foo(ttlMillis: Long = <!TYPE_MISMATCH!>5 * 60 * 1000<!>) {}
const val cacheSize: Long = <!TYPE_MISMATCH!>4096 * 4<!>
@@ -1,4 +0,0 @@
package
public const val cacheSize: kotlin.Long = 16384
public fun foo(/*0*/ ttlMillis: kotlin.Long = ...): kotlin.Unit
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321). // This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321).
// Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895). // Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895).
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321). // This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321).
// Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895). // Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895).
@@ -1,116 +0,0 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_STDLIB
// ISSUE: KT-38895
fun takeByte(b: Byte) {}
fun takeInt(b: Int) {}
fun takeLong(b: Long) {}
fun testByteBinaryOperators() {
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 + 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 - 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 * 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 / 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 % 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.plus(1)<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.minus(1)<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.times(1)<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.div(1)<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.rem(1)<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 shl 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 shr 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 ushr 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 and 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 or 1<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2 xor 1<!>)
}
fun testByteUnaryOperators() {
// No mismatch
takeByte(+1)
takeByte(-1)
// Mismatch
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.unaryPlus()<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.unaryMinus()<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>2.inv()<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)
takeByte(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
}
fun testLongBinaryOperators() {
takeLong(2 + 1)
takeLong(2 - 1)
takeLong(2 * 1)
takeLong(2 / 1)
takeLong(2 % 1)
takeLong(2.plus(1))
takeLong(2.minus(1))
takeLong(2.times(1))
takeLong(2.div(1))
takeLong(2.rem(1))
takeLong(2 shl 1)
takeLong(2 shr 1)
takeLong(2 ushr 1)
takeLong(2 and 1)
takeLong(2 or 1)
takeLong(2 xor 1)
// positive
takeLong(2 * 100000000000)
}
fun testLongUnaryOperators() {
// No mismatch
takeLong(+1)
takeLong(-1)
// Mismatch
takeLong(2.unaryPlus())
takeLong(2.unaryMinus())
takeLong(2.inv())
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
}
fun testIntBinaryOperators() {
takeInt(2 + 1)
takeInt(2 - 1)
takeInt(2 * 1)
takeInt(2 / 1)
takeInt(2 % 1)
takeInt(2.plus(1))
takeInt(2.minus(1))
takeInt(2.times(1))
takeInt(2.div(1))
takeInt(2.rem(1))
takeInt(2 shl 1)
takeInt(2 shr 1)
takeInt(2 ushr 1)
takeInt(2 and 1)
takeInt(2 or 1)
takeInt(2 xor 1)
}
fun testIntUnaryOperators() {
takeInt(+1)
takeInt(-1)
takeInt(2.unaryPlus())
takeInt(2.unaryMinus())
takeInt(2.inv())
takeInt(1.inc())
takeInt(1.dec())
}
fun testNoOperators() {
takeByte(1)
takeInt(1)
takeLong(1)
}
@@ -1,116 +0,0 @@
// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_STDLIB
// ISSUE: KT-38895
fun takeByte(b: Byte) {}
fun takeInt(b: Int) {}
fun takeLong(b: Long) {}
fun testByteBinaryOperators() {
takeByte(<!TYPE_MISMATCH!>2 + 1<!>)
takeByte(<!TYPE_MISMATCH!>2 - 1<!>)
takeByte(<!TYPE_MISMATCH!>2 * 1<!>)
takeByte(<!TYPE_MISMATCH!>2 / 1<!>)
takeByte(<!TYPE_MISMATCH!>2 % 1<!>)
takeByte(<!TYPE_MISMATCH!>2.plus(1)<!>)
takeByte(<!TYPE_MISMATCH!>2.minus(1)<!>)
takeByte(<!TYPE_MISMATCH!>2.times(1)<!>)
takeByte(<!TYPE_MISMATCH!>2.div(1)<!>)
takeByte(<!TYPE_MISMATCH!>2.rem(1)<!>)
takeByte(<!TYPE_MISMATCH!>2 shl 1<!>)
takeByte(<!TYPE_MISMATCH!>2 shr 1<!>)
takeByte(<!TYPE_MISMATCH!>2 ushr 1<!>)
takeByte(<!TYPE_MISMATCH!>2 and 1<!>)
takeByte(<!TYPE_MISMATCH!>2 or 1<!>)
takeByte(<!TYPE_MISMATCH!>2 xor 1<!>)
}
fun testByteUnaryOperators() {
// No mismatch
takeByte(+1)
takeByte(-1)
// Mismatch
takeByte(<!TYPE_MISMATCH!>2.unaryPlus()<!>)
takeByte(<!TYPE_MISMATCH!>2.unaryMinus()<!>)
takeByte(<!TYPE_MISMATCH!>2.inv()<!>)
takeByte(<!TYPE_MISMATCH!>1.inc()<!>)
takeByte(<!TYPE_MISMATCH!>1.dec()<!>)
}
fun testLongBinaryOperators() {
takeLong(<!TYPE_MISMATCH!>2 + 1<!>)
takeLong(<!TYPE_MISMATCH!>2 - 1<!>)
takeLong(<!TYPE_MISMATCH!>2 * 1<!>)
takeLong(<!TYPE_MISMATCH!>2 / 1<!>)
takeLong(<!TYPE_MISMATCH!>2 % 1<!>)
takeLong(<!TYPE_MISMATCH!>2.plus(1)<!>)
takeLong(<!TYPE_MISMATCH!>2.minus(1)<!>)
takeLong(<!TYPE_MISMATCH!>2.times(1)<!>)
takeLong(<!TYPE_MISMATCH!>2.div(1)<!>)
takeLong(<!TYPE_MISMATCH!>2.rem(1)<!>)
takeLong(<!TYPE_MISMATCH!>2 shl 1<!>)
takeLong(<!TYPE_MISMATCH!>2 shr 1<!>)
takeLong(<!TYPE_MISMATCH!>2 ushr 1<!>)
takeLong(<!TYPE_MISMATCH!>2 and 1<!>)
takeLong(<!TYPE_MISMATCH!>2 or 1<!>)
takeLong(<!TYPE_MISMATCH!>2 xor 1<!>)
// positive
takeLong(2 * 100000000000)
}
fun testLongUnaryOperators() {
// No mismatch
takeLong(+1)
takeLong(-1)
// Mismatch
takeLong(<!TYPE_MISMATCH!>2.unaryPlus()<!>)
takeLong(<!TYPE_MISMATCH!>2.unaryMinus()<!>)
takeLong(<!TYPE_MISMATCH!>2.inv()<!>)
takeLong(<!TYPE_MISMATCH!>1.inc()<!>)
takeLong(<!TYPE_MISMATCH!>1.dec()<!>)
}
fun testIntBinaryOperators() {
takeInt(2 + 1)
takeInt(2 - 1)
takeInt(2 * 1)
takeInt(2 / 1)
takeInt(2 % 1)
takeInt(2.plus(1))
takeInt(2.minus(1))
takeInt(2.times(1))
takeInt(2.div(1))
takeInt(2.rem(1))
takeInt(2 shl 1)
takeInt(2 shr 1)
takeInt(2 ushr 1)
takeInt(2 and 1)
takeInt(2 or 1)
takeInt(2 xor 1)
}
fun testIntUnaryOperators() {
takeInt(+1)
takeInt(-1)
takeInt(2.unaryPlus())
takeInt(2.unaryMinus())
takeInt(2.inv())
takeInt(1.inc())
takeInt(1.dec())
}
fun testNoOperators() {
takeByte(1)
takeInt(1)
takeLong(1)
}
@@ -1,12 +0,0 @@
package
public fun takeByte(/*0*/ b: kotlin.Byte): kotlin.Unit
public fun takeInt(/*0*/ b: kotlin.Int): kotlin.Unit
public fun takeLong(/*0*/ b: kotlin.Long): kotlin.Unit
public fun testByteBinaryOperators(): kotlin.Unit
public fun testByteUnaryOperators(): kotlin.Unit
public fun testIntBinaryOperators(): kotlin.Unit
public fun testIntUnaryOperators(): kotlin.Unit
public fun testLongBinaryOperators(): kotlin.Unit
public fun testLongUnaryOperators(): kotlin.Unit
public fun testNoOperators(): kotlin.Unit
@@ -1,4 +1,3 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_STDLIB // WITH_STDLIB
// ISSUE: KT-38895 // ISSUE: KT-38895
@@ -1,4 +1,3 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// WITH_STDLIB // WITH_STDLIB
// ISSUE: KT-38895 // ISSUE: KT-38895
+1 -1
View File
@@ -1,5 +1,5 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: JVM_IR // IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
// SKIP_KT_DUMP // SKIP_KT_DUMP
// This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321). // This test exists only to check that we don't accidentally break the buggy behavior of the old JVM backend in JVM IR (KT-42321).
// Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895). // Feel free to remove it as soon as there's no language version where such code is allowed (KT-38895).
@@ -1,6 +1,5 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// IGNORE_BACKEND_K2: ANY // IGNORE_BACKEND_K2: ANY
// For reasons this test is ignored, go to KT-46419 // FIR status: KT-46419, ILT conversions to Byte and Short are not supported by design
val test1: Long = 42 val test1: Long = 42
val test2: Short = 42 val test2: Short = 42
@@ -22291,15 +22291,9 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
} }
@Test @Test
@TestMetadata("kt48361_disabled.kt") @TestMetadata("kt48361.kt")
public void testKt48361_disabled() throws Exception { public void testKt48361() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); runTest("compiler/testData/diagnostics/tests/numbers/kt48361.kt");
}
@Test
@TestMetadata("kt48361_enabled.kt")
public void testKt48361_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt");
} }
@Test @Test
@@ -22308,12 +22302,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt"); runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt");
} }
@Test
@TestMetadata("newLiteralOperatorsResolution_newResolve.kt")
public void testNewLiteralOperatorsResolution_newResolve() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.kt");
}
@Test @Test
@TestMetadata("newLiteralOperatorsResolution_warning.kt") @TestMetadata("newLiteralOperatorsResolution_warning.kt")
public void testNewLiteralOperatorsResolution_warning() throws Exception { public void testNewLiteralOperatorsResolution_warning() throws Exception {
@@ -128,12 +128,6 @@ abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() {
} }
// ----------------------- constant evaluation tests ----------------------- // ----------------------- constant evaluation tests -----------------------
forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/*") {
defaultDirectives {
LANGUAGE with "-ApproximateIntegerLiteralTypesInReceiverPosition"
}
}
forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/constant/*") { forTestsMatching("compiler/testData/diagnostics/tests/constantEvaluator/constant/*") {
defaultDirectives { defaultDirectives {
CHECK_COMPILE_TIME_VALUES with ConstantValuesHandler.Mode.Constant CHECK_COMPILE_TIME_VALUES with ConstantValuesHandler.Mode.Constant
@@ -287,9 +287,6 @@ enum class LanguageFeature(
// Disabled for indefinite time. See KT-53751 // Disabled for indefinite time. See KT-53751
IgnoreNullabilityForErasedValueParameters(sinceVersion = null, kind = BUG_FIX), IgnoreNullabilityForErasedValueParameters(sinceVersion = null, kind = BUG_FIX),
// Disabled for indefinite time. See KT-48535 and related discussion
ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null),
// Disabled for indefinite time. Disables restrictions of builder inference without annotation // Disabled for indefinite time. Disables restrictions of builder inference without annotation
// Note: In 1.7.0, builder inference without annotation was introduced. // Note: In 1.7.0, builder inference without annotation was introduced.
// However, later we encountered various situations when it works incorrectly, and decided to forbid them. // However, later we encountered various situations when it works incorrectly, and decided to forbid them.
@@ -28,7 +28,7 @@ interface CompileTimeConstant<out T> {
val isError: Boolean val isError: Boolean
get() = false get() = false
val parameters: CompileTimeConstant.Parameters val parameters: Parameters
val moduleDescriptor: ModuleDescriptor val moduleDescriptor: ModuleDescriptor
@@ -58,8 +58,7 @@ interface CompileTimeConstant<out T> {
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 has `ImplicitIntegerCoercion` annotation
val isConvertableConstVal: Boolean, val isConvertableConstVal: Boolean
val dontCreateILT: Boolean
) )
override fun equals(other: Any?): Boolean override fun equals(other: Any?): Boolean
@@ -150,8 +149,7 @@ class IntegerValueTypeConstant(
isUnsignedLongNumberLiteral = parameters.isUnsignedLongNumberLiteral, isUnsignedLongNumberLiteral = parameters.isUnsignedLongNumberLiteral,
usesVariableAsConstant = parameters.usesVariableAsConstant, usesVariableAsConstant = parameters.usesVariableAsConstant,
usesNonConstValAsConstant = parameters.usesNonConstValAsConstant, usesNonConstValAsConstant = parameters.usesNonConstValAsConstant,
isConvertableConstVal = parameters.isConvertableConstVal, isConvertableConstVal = parameters.isConvertableConstVal
dontCreateILT = false
) )
return IntegerValueTypeConstant(value, module, newParameters, newInferenceEnabled, convertedFromSigned = true) return IntegerValueTypeConstant(value, module, newParameters, newInferenceEnabled, convertedFromSigned = true)
@@ -165,8 +163,7 @@ class IntegerValueTypeConstant(
isUnsignedLongNumberLiteral = parameters.isUnsignedLongNumberLiteral, isUnsignedLongNumberLiteral = parameters.isUnsignedLongNumberLiteral,
usesVariableAsConstant = parameters.usesVariableAsConstant, usesVariableAsConstant = parameters.usesVariableAsConstant,
usesNonConstValAsConstant = parameters.usesNonConstValAsConstant, usesNonConstValAsConstant = parameters.usesNonConstValAsConstant,
isConvertableConstVal = parameters.isConvertableConstVal, isConvertableConstVal = parameters.isConvertableConstVal
dontCreateILT = false
) )
return IntegerValueTypeConstant(value, module, newParameters, newInferenceEnabled, convertedFromSigned = true) return IntegerValueTypeConstant(value, module, newParameters, newInferenceEnabled, convertedFromSigned = true)
@@ -1,4 +1,3 @@
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// EXPECTED_REACHABLE_NODES: 1375 // EXPECTED_REACHABLE_NODES: 1375
package foo package foo
@@ -14,4 +13,4 @@ fun box(): String {
return "OK" return "OK"
} }
fun id(x: Long) = x fun id(x: Long) = x