From 40614507d363054d7880662c8973698cdc60f463 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 23 Aug 2021 11:36:14 +0300 Subject: [PATCH] [FE 1.0] Report warning about new IL operator resolve in initializers and default values ^KT-48361 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 12 +++++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 +++++++++++ .../VariableTypeAndInitializerResolver.kt | 11 +++++++++- ...chemeOfIntegerOperatorResolutionChecker.kt | 10 ++++++++- .../evaluate/ConstantExpressionEvaluator.kt | 21 +++++++++++++------ .../ExpressionTypingVisitorForStatements.java | 2 +- .../expressions/ValueParameterResolver.kt | 8 +++++++ .../testData/codegen/box/binaryOp/call.kt | 1 + .../codegen/box/binaryOp/callNullable.kt | 1 + .../codegen/box/binaryOp/intrinsic.kt | 1 + .../codegen/box/binaryOp/intrinsicNullable.kt | 1 + .../codegen/box/binaryOp/overflowLong.kt | 1 + compiler/testData/codegen/box/unaryOp/call.kt | 1 + .../codegen/box/unaryOp/callNullable.kt | 1 + .../codegen/bytecodeText/constants/byte.kt | 1 + .../codegen/bytecodeText/constants/short.kt | 1 + .../evaluate/binaryMinusIndependentExpType.kt | 8 +++---- .../binaryMinusIndependentExpType.txt | 6 +++--- .../tests/evaluate/parentesized.fir.kt | 12 ----------- .../tests/evaluate/parentesized.kt | 9 ++++---- .../tests/evaluate/parentesized.txt | 7 ++++--- .../tests/numbers/kt48361_disabled.fir.kt | 5 +++++ .../tests/numbers/kt48361_disabled.kt | 5 +++++ .../tests/numbers/kt48361_disabled.txt | 5 +++++ .../tests/numbers/kt48361_enabled.kt | 7 +++++++ .../tests/numbers/kt48361_enabled.txt | 4 ++++ .../primitivesImplicitConversions.kt | 1 + .../test/runners/DiagnosticTestGenerated.java | 12 +++++++++++ ...CompilerTestFE10TestdataTestGenerated.java | 12 +++++++++++ 29 files changed, 143 insertions(+), 35 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/kt48361_disabled.txt create mode 100644 compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/kt48361_enabled.txt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 0e5611afbfc..6fb2a3c19c9 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -20257,6 +20257,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt"); } + @Test + @TestMetadata("kt48361_disabled.kt") + public void testKt48361_disabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); + } + + @Test + @TestMetadata("kt48361_enabled.kt") + public void testKt48361_enabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt"); + } + @Test @TestMetadata("literalReceiverWithIntegerValueType.kt") public void testLiteralReceiverWithIntegerValueType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index a41aefe3098..a1cd54e9754 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -20257,6 +20257,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt"); } + @Test + @TestMetadata("kt48361_disabled.kt") + public void testKt48361_disabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); + } + + @Test + @TestMetadata("kt48361_enabled.kt") + public void testKt48361_enabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt"); + } + @Test @TestMetadata("literalReceiverWithIntegerValueType.kt") public void testLiteralReceiverWithIntegerValueType() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt index 5addb56506f..7562c8c0407 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtVariableDeclaration import org.jetbrains.kotlin.resolve.DescriptorResolver.transformAnonymousTypeIfNeeded +import org.jetbrains.kotlin.resolve.calls.checkers.NewSchemeOfIntegerOperatorResolutionChecker import org.jetbrains.kotlin.resolve.calls.components.InferenceSession import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator @@ -124,6 +125,13 @@ class VariableTypeAndInitializerResolver( val initializer = variable.initializer val initializerType = expressionTypingServices.safeGetType(scope, initializer!!, variableType, dataFlowInfo, inferenceSession, trace) + NewSchemeOfIntegerOperatorResolutionChecker.checkArgument( + variableType, + initializer, + languageVersionSettings, + trace, + constantExpressionEvaluator.module + ) val constant = constantExpressionEvaluator.evaluateExpression(initializer, trace, initializerType) ?: return@computeInitializer null @@ -131,7 +139,8 @@ class VariableTypeAndInitializerResolver( trace.report(Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION.on(initializer)) } - constant.toConstantValue(initializerType) + val qqq = constant.toConstantValue(initializerType) + qqq }, null ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt index 91b98f1760e..8d3363be5e0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers 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.SimpleFunctionDescriptor import org.jetbrains.kotlin.diagnostics.Errors @@ -52,7 +53,14 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { } @JvmStatic - fun checkArgument(expectedType: KotlinType, argument: KtExpression, trace: BindingTrace, moduleDescriptor: ModuleDescriptor) { + fun checkArgument( + expectedType: KotlinType, + argument: KtExpression, + languageVersionSettings: LanguageVersionSettings, + trace: BindingTrace, + moduleDescriptor: ModuleDescriptor + ) { + if (languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition)) return val type = expectedType.lowerIfFlexible() if (type.isPrimitiveNumberOrNullableType()) { checkArgumentImpl(type, KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index 9215191f8cb..8f6b1f9e817 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl @@ -47,6 +48,7 @@ import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.isBoolean import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.util.OperatorNameConventions +import org.jetbrains.kotlin.utils.addToStdlib.runIf import java.math.BigInteger import java.util.* @@ -379,7 +381,7 @@ private class ConstantExpressionEvaluatorVisitor( private val languageVersionSettings = constantExpressionEvaluator.languageVersionSettings private val builtIns = constantExpressionEvaluator.module.builtIns private val defaultValueForDontCreateIntegerLiteralType = - languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition) + languageVersionSettings.supportsFeature(ApproximateIntegerLiteralTypesInReceiverPosition) fun evaluate(expression: KtExpression, expectedType: KotlinType?): CompileTimeConstant<*>? { val recordedCompileTimeConstant = ConstantExpressionEvaluator.getPossiblyErrorConstant(expression, trace.bindingContext) @@ -666,10 +668,12 @@ private class ConstantExpressionEvaluatorVisitor( val usesNonConstValAsConstant = usesNonConstValAsConstant(argumentForReceiver.expression) val isNumberConversionMethod = resultingDescriptorName in OperatorConventions.NUMBER_CONVERSIONS val isCharCode = argumentForReceiver.ctcType == CHAR && resultingDescriptorName == StandardNames.CHAR_CODE - val dontCreateILT = !isUnaryPlusMinus && !hasIntegerLiteralType(receiverExpression) + val dontCreateILT = defaultValueForDontCreateIntegerLiteralType && + !isUnaryPlusMinus && + !hasIntegerLiteralType(receiverExpression) return createConstant( result, - expectedType, + expectedType.takeUnless { dontCreateILT }, CompileTimeConstant.Parameters( canBeUsedInAnnotation, !isNumberConversionMethod && !isCharCode && isArgumentPure, @@ -678,7 +682,7 @@ private class ConstantExpressionEvaluatorVisitor( usesVariableAsConstant, usesNonConstValAsConstant, isConvertableConstVal = false, - dontCreateILT = defaultValueForDontCreateIntegerLiteralType && dontCreateILT + dontCreateILT = dontCreateILT ) ) } else if (argumentsEntrySet.size == 1) { @@ -713,6 +717,7 @@ private class ConstantExpressionEvaluatorVisitor( usesVariableAsConstant(argumentForReceiver.expression) || usesVariableAsConstant(argumentForParameter.expression) val usesNonConstValAsConstant = usesNonConstValAsConstant(argumentForReceiver.expression) || usesNonConstValAsConstant(argumentForParameter.expression) + val dontCreateILT = defaultValueForDontCreateIntegerLiteralType && !hasIntegerLiteralType(receiverExpression) val parameters = CompileTimeConstant.Parameters( canBeUsedInAnnotation, areArgumentsPure, @@ -721,13 +726,17 @@ private class ConstantExpressionEvaluatorVisitor( usesVariableAsConstant, usesNonConstValAsConstant, isConvertableConstVal = false, - dontCreateILT = defaultValueForDontCreateIntegerLiteralType && !hasIntegerLiteralType(receiverExpression) + dontCreateILT = dontCreateILT ) return when (resultingDescriptorName) { OperatorNameConventions.COMPARE_TO -> createCompileTimeConstantForCompareTo(result, callExpression)?.wrap(parameters) OperatorNameConventions.EQUALS -> createCompileTimeConstantForEquals(result, callExpression)?.wrap(parameters) else -> { - createConstant(result, expectedType, parameters) + createConstant( + result, + expectedType.takeUnless { dontCreateILT }, + parameters + ) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java index 0e456a634a6..d3c5f3f89b0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java @@ -418,7 +418,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito DataFlowValue rightValue = components.dataFlowValueFactory.createDataFlowValue(right, rightType, context); // 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)); - NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(expectedType, right, context.trace, components.moduleDescriptor); + NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(expectedType, right, context.languageVersionSettings, context.trace, components.moduleDescriptor); } } else { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ValueParameterResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ValueParameterResolver.kt index 4a7aee5bb16..fd62192a745 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ValueParameterResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ValueParameterResolver.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.DescriptorResolver import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.calls.checkers.NewSchemeOfIntegerOperatorResolutionChecker import org.jetbrains.kotlin.resolve.calls.components.InferenceSession import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory @@ -71,6 +72,13 @@ class ValueParameterResolver( val defaultValue = parameter.defaultValue ?: return val type = valueParameterDescriptor.type expressionTypingServices.getTypeInfo(defaultValue, context.replaceExpectedType(type)) + NewSchemeOfIntegerOperatorResolutionChecker.checkArgument( + type, + defaultValue, + context.languageVersionSettings, + context.trace, + constantExpressionEvaluator.module + ) if (DescriptorUtils.isAnnotationClass(DescriptorResolver.getContainingClass(context.scope))) { val constant = constantExpressionEvaluator.evaluateExpression(defaultValue, context.trace, type) if ((constant == null || constant.usesNonConstValAsConstant) && !type.isError) { diff --git a/compiler/testData/codegen/box/binaryOp/call.kt b/compiler/testData/codegen/box/binaryOp/call.kt index 514fca14a7f..26550e06d4a 100644 --- a/compiler/testData/codegen/box/binaryOp/call.kt +++ b/compiler/testData/codegen/box/binaryOp/call.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/binaryOp/callNullable.kt b/compiler/testData/codegen/box/binaryOp/callNullable.kt index 4d4de041025..7990951a557 100644 --- a/compiler/testData/codegen/box/binaryOp/callNullable.kt +++ b/compiler/testData/codegen/box/binaryOp/callNullable.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/binaryOp/intrinsic.kt b/compiler/testData/codegen/box/binaryOp/intrinsic.kt index 0b6f8edaed1..1ff278186a4 100644 --- a/compiler/testData/codegen/box/binaryOp/intrinsic.kt +++ b/compiler/testData/codegen/box/binaryOp/intrinsic.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/binaryOp/intrinsicNullable.kt b/compiler/testData/codegen/box/binaryOp/intrinsicNullable.kt index ffe4cfbea63..5ca8c00d13c 100644 --- a/compiler/testData/codegen/box/binaryOp/intrinsicNullable.kt +++ b/compiler/testData/codegen/box/binaryOp/intrinsicNullable.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/binaryOp/overflowLong.kt b/compiler/testData/codegen/box/binaryOp/overflowLong.kt index 42932e2b23a..e5e45f64999 100644 --- a/compiler/testData/codegen/box/binaryOp/overflowLong.kt +++ b/compiler/testData/codegen/box/binaryOp/overflowLong.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/unaryOp/call.kt b/compiler/testData/codegen/box/unaryOp/call.kt index a26eea07992..e87bada56b9 100644 --- a/compiler/testData/codegen/box/unaryOp/call.kt +++ b/compiler/testData/codegen/box/unaryOp/call.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/box/unaryOp/callNullable.kt b/compiler/testData/codegen/box/unaryOp/callNullable.kt index ae9762547ba..5c6f6c3fa6d 100644 --- a/compiler/testData/codegen/box/unaryOp/callNullable.kt +++ b/compiler/testData/codegen/box/unaryOp/callNullable.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/bytecodeText/constants/byte.kt b/compiler/testData/codegen/bytecodeText/constants/byte.kt index 798aa8e7205..8dede564aa1 100644 --- a/compiler/testData/codegen/bytecodeText/constants/byte.kt +++ b/compiler/testData/codegen/bytecodeText/constants/byte.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/codegen/bytecodeText/constants/short.kt b/compiler/testData/codegen/bytecodeText/constants/short.kt index 3a1992d04f9..190a50095b1 100644 --- a/compiler/testData/codegen/bytecodeText/constants/short.kt +++ b/compiler/testData/codegen/bytecodeText/constants/short.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: JVM_IR // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt index ae12df8f6b6..a5c5f5bfe1e 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt @@ -1,7 +1,7 @@ val p1: Int = 1 - 1 -val p2: Long = 1 - 1 -val p3: Byte = 1 - 1 -val p4: Short = 1 - 1 +val p2: Long = 1 - 1 +val p3: Byte = 1 - 1 +val p4: Short = 1 - 1 val l1: Long = 1 - 1.toLong() val l2: Byte = 1 - 1.toLong() @@ -21,4 +21,4 @@ val i4: Short = 1 - 1.toInt() val s1: Byte = 1 - 1.toShort() val s2: Int = 1 - 1.toShort() val s3: Long = 1 - 1.toShort() -val s4: Short = 1 - 1.toShort() \ No newline at end of file +val s4: Short = 1 - 1.toShort() diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.txt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.txt index 789c278a03d..b63075dcd1c 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.txt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.txt @@ -13,9 +13,9 @@ public val l2: kotlin.Byte = 0.toLong() public val l3: kotlin.Int = 0.toLong() public val l4: kotlin.Short = 0.toLong() public val p1: kotlin.Int = 0 -public val p2: kotlin.Long = 0.toLong() -public val p3: kotlin.Byte = 0.toByte() -public val p4: kotlin.Short = 0.toShort() +public val p2: kotlin.Long = 0 +public val p3: kotlin.Byte = 0 +public val p4: kotlin.Short = 0 public val s1: kotlin.Byte = 0 public val s2: kotlin.Int = 0 public val s3: kotlin.Long = 0 diff --git a/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt b/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt deleted file mode 100644 index eb7fa7afede..00000000000 --- a/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -val p1: Byte = (1 + 2) * 2 -val p2: Short = (1 + 2) * 2 -val p3: Int = (1 + 2) * 2 -val p4: Long = (1 + 2) * 2 - -val b1: Byte = (1.toByte() + 2) * 2 -val b2: Short = (1.toShort() + 2) * 2 -val b3: Int = (1.toInt() + 2) * 2 -val b4: Long = (1.toLong() + 2) * 2 - -val i1: Int = (1.toByte() + 2) * 2 -val i2: Int = (1.toShort() + 2) * 2 diff --git a/compiler/testData/diagnostics/tests/evaluate/parentesized.kt b/compiler/testData/diagnostics/tests/evaluate/parentesized.kt index 8070e900c7d..75bf9896b1f 100644 --- a/compiler/testData/diagnostics/tests/evaluate/parentesized.kt +++ b/compiler/testData/diagnostics/tests/evaluate/parentesized.kt @@ -1,7 +1,8 @@ -val p1: Byte = (1 + 2) * 2 -val p2: Short = (1 + 2) * 2 +// FIR_IDENTICAL +val p1: Byte = (1 + 2) * 2 +val p2: Short = (1 + 2) * 2 val p3: Int = (1 + 2) * 2 -val p4: Long = (1 + 2) * 2 +val p4: Long = (1 + 2) * 2 val b1: Byte = (1.toByte() + 2) * 2 val b2: Short = (1.toShort() + 2) * 2 @@ -9,4 +10,4 @@ val b3: Int = (1.toInt() + 2) * 2 val b4: Long = (1.toLong() + 2) * 2 val i1: Int = (1.toByte() + 2) * 2 -val i2: Int = (1.toShort() + 2) * 2 \ No newline at end of file +val i2: Int = (1.toShort() + 2) * 2 diff --git a/compiler/testData/diagnostics/tests/evaluate/parentesized.txt b/compiler/testData/diagnostics/tests/evaluate/parentesized.txt index 5fb47d1328a..8748b6d2aa3 100644 --- a/compiler/testData/diagnostics/tests/evaluate/parentesized.txt +++ b/compiler/testData/diagnostics/tests/evaluate/parentesized.txt @@ -6,7 +6,8 @@ public val b3: kotlin.Int = 6 public val b4: kotlin.Long = 6.toLong() public val i1: kotlin.Int = 6 public val i2: kotlin.Int = 6 -public val p1: kotlin.Byte = 6.toByte() -public val p2: kotlin.Short = 6.toShort() +public val p1: kotlin.Byte = 6 +public val p2: kotlin.Short = 6 public val p3: kotlin.Int = 6 -public val p4: kotlin.Long = 6.toLong() +public val p4: kotlin.Long = 6 + diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt new file mode 100644 index 00000000000..cd4a8c44a46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition + +fun foo(ttlMillis: Long = 5 * 60 * 1000) {} + +const val cacheSize: Long = 4096 * 4 diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt new file mode 100644 index 00000000000..95e8e7a1318 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition + +fun foo(ttlMillis: Long = 5 * 60 * 1000) {} + +const val cacheSize: Long = 4096 * 4 diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.txt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.txt new file mode 100644 index 00000000000..8a15e35253b --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.txt @@ -0,0 +1,5 @@ +package + +public const val cacheSize: kotlin.Long = 16384.toLong() +public fun foo(/*0*/ ttlMillis: kotlin.Long = ...): kotlin.Unit + diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt new file mode 100644 index 00000000000..f2dffd6c754 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt @@ -0,0 +1,7 @@ +// FIR_IDENTICAL +// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition + +fun foo(ttlMillis: Long = 5 * 60 * 1000) {} + +const val cacheSize: Long = 4096 * 4 + diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.txt b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.txt new file mode 100644 index 00000000000..9cf7a8a24cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.txt @@ -0,0 +1,4 @@ +package + +public const val cacheSize: kotlin.Long = 16384 +public fun foo(/*0*/ ttlMillis: kotlin.Long = ...): kotlin.Unit diff --git a/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.kt b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.kt index 16e5a067555..d3e44843321 100644 --- a/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.kt +++ b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.kt @@ -1,3 +1,4 @@ +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // IGNORE_BACKEND_FIR: ANY // For reasons this test is ignored, go to KT-46419 diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 6a529d9ed86..654dd83cf52 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -20263,6 +20263,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt"); } + @Test + @TestMetadata("kt48361_disabled.kt") + public void testKt48361_disabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); + } + + @Test + @TestMetadata("kt48361_enabled.kt") + public void testKt48361_enabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt"); + } + @Test @TestMetadata("literalReceiverWithIntegerValueType.kt") public void testLiteralReceiverWithIntegerValueType() throws Exception { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index c94f90b006f..885bbb7f104 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -20257,6 +20257,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt"); } + @Test + @TestMetadata("kt48361_disabled.kt") + public void testKt48361_disabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt"); + } + + @Test + @TestMetadata("kt48361_enabled.kt") + public void testKt48361_enabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt"); + } + @Test @TestMetadata("literalReceiverWithIntegerValueType.kt") public void testLiteralReceiverWithIntegerValueType() throws Exception {