diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/PublicApproximatorConfiguration.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/PublicApproximatorConfiguration.kt index fc5949a7e97..150f75fe4d1 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/PublicApproximatorConfiguration.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/utils/PublicApproximatorConfiguration.kt @@ -12,7 +12,7 @@ internal object PublicApproximatorConfiguration : TypeApproximatorConfiguration. override val allFlexible: Boolean get() = false override val errorType: Boolean get() = true override val definitelyNotNullType: Boolean get() = false - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true override val localTypes: Boolean get() = true -} \ No newline at end of file +} diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirSymbol.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirSymbol.kt index 5f174ca60be..25100e44fda 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirSymbol.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirSymbol.kt @@ -13,10 +13,12 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirModuleResolveSta import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin +import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty import org.jetbrains.kotlin.fir.originalIfFakeOverride import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.scopes.impl.importedFromObjectData +import org.jetbrains.kotlin.fir.scopes.impl.originalForWrappedIntegerOperator import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol internal interface KtFirSymbol> : KtSymbol, ValidityTokenOwner { @@ -64,6 +66,12 @@ internal tailrec fun FirDeclaration.ktSymbolOrigin(): KtSymbolOrigin = when (ori importedFromObjectData.original.ktSymbolOrigin() } + FirDeclarationOrigin.WrappedIntegerOperator -> { + val original = (this as FirSimpleFunction).originalForWrappedIntegerOperator?.fir + ?: error("Declaration has WrappedIntegerOperator origin, but no originalForWrappedIntegerOperator present") + + original.ktSymbolOrigin() + } else -> { val overridden = (this as? FirCallableDeclaration)?.originalIfFakeOverride() ?: throw InvalidFirDeclarationOriginForSymbol(this) diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/PublicTypeApproximator.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/PublicTypeApproximator.kt index bcbd30804e4..b10dc3bb3ce 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/PublicTypeApproximator.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/PublicTypeApproximator.kt @@ -26,7 +26,7 @@ internal object PublicTypeApproximator { override val allFlexible: Boolean get() = false override val errorType: Boolean get() = true override val definitelyNotNullType: Boolean get() = false - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true override val anonymous: Boolean get() = true } diff --git a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/binaryExpression.txt b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/binaryExpression.txt index 9b7a8a69c98..5f76f41d8a7 100644 --- a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/binaryExpression.txt +++ b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/binaryExpression.txt @@ -1,5 +1,5 @@ KT element: KtBinaryExpression -FIR element: FirFunctionCallImpl +FIR element: FirIntegerLiteralOperatorCallImpl FIR source kind: KtRealSourceElementKind FIR element rendered: diff --git a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/parenthesizedExpression.txt b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/parenthesizedExpression.txt index ad0d3785beb..db3e419f303 100644 --- a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/parenthesizedExpression.txt +++ b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/parenthesizedExpression.txt @@ -1,5 +1,5 @@ KT element: KtParenthesizedExpression -FIR element: FirFunctionCallImpl +FIR element: FirIntegerLiteralOperatorCallImpl FIR source kind: KtRealSourceElementKind FIR element rendered: diff --git a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/stringTemplateExpressionEntry.txt b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/stringTemplateExpressionEntry.txt index 23909daa4e3..3bd1a93e77c 100644 --- a/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/stringTemplateExpressionEntry.txt +++ b/analysis/low-level-api-fir/testdata/getOrBuildFir/expressions/stringTemplateExpressionEntry.txt @@ -1,6 +1,6 @@ KT element: KtBlockStringTemplateEntry -FIR element: FirFunctionCallImpl +FIR element: FirIntegerLiteralOperatorCallImpl FIR source kind: KtRealSourceElementKind FIR element rendered: -Int(1).R|kotlin/Int.plus|(Int(2)) \ No newline at end of file +Int(1).R|kotlin/Int.plus|(Int(2)) diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 661ba671258..db3a97cdc23 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -17477,6 +17477,28 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/integerLiterals") + @TestDataPath("$PROJECT_ROOT") + public class IntegerLiterals { + @Test + public void testAllFilesPresentInIntegerLiterals() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("intToLongConversion.kt") + public void testIntToLongConversion() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt"); + } + + @Test + @TestMetadata("literalsInInference.kt") + public void testLiteralsInInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/j+k") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/lambda.fir.txt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/lambda.fir.txt index f3517513af7..bdf9eb5f4af 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/lambda.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/lambda.fir.txt @@ -1,6 +1,6 @@ FILE: lambda.kt public final fun f(t: R|(@R|kotlin/ParameterName|(name = String(v)) kotlin/Int) -> kotlin/Unit|): R|kotlin/Unit| { - Int(1).R|kotlin/run|(R|/t|) + Int(1).R|kotlin/run|(R|/t|) } public final fun main(): R|kotlin/Unit| { R|/f|( = f@fun (i: R|@R|kotlin/ParameterName|(name = String(v)) kotlin/Int|): R|kotlin/Unit| { 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 6378771b6f2..b2f1bf1ec7a 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 @@ -17477,6 +17477,28 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/integerLiterals") + @TestDataPath("$PROJECT_ROOT") + public class IntegerLiterals { + @Test + public void testAllFilesPresentInIntegerLiterals() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("intToLongConversion.kt") + public void testIntToLongConversion() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt"); + } + + @Test + @TestMetadata("literalsInInference.kt") + public void testLiteralsInInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/j+k") @TestDataPath("$PROJECT_ROOT") 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 57df8579832..ba65bc8c193 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 @@ -17477,6 +17477,28 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/integerLiterals") + @TestDataPath("$PROJECT_ROOT") + public class IntegerLiterals { + @Test + public void testAllFilesPresentInIntegerLiterals() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("intToLongConversion.kt") + public void testIntToLongConversion() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt"); + } + + @Test + @TestMetadata("literalsInInference.kt") + public void testLiteralsInInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/j+k") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt index da9af3eae3a..4dfe2568951 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt @@ -31,6 +31,7 @@ fun main(args: Array) { alias("QualifiedAccessExpressionChecker") alias("CallChecker") alias("FunctionCallChecker") + alias("IntegerLiteralOperatorCallChecker") alias("VariableAssignmentChecker") alias("TryExpressionChecker") alias("WhenExpressionChecker") diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt index 1ebe56b13b3..f7755576961 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt @@ -23,6 +23,8 @@ class ComposedExpressionCheckers : ExpressionCheckers() { get() = _callCheckers override val functionCallCheckers: Set get() = _functionCallCheckers + override val integerLiteralOperatorCallCheckers: Set + get() = _integerLiteralOperatorCallCheckers override val variableAssignmentCheckers: Set get() = _variableAssignmentCheckers override val tryExpressionCheckers: Set @@ -79,6 +81,7 @@ class ComposedExpressionCheckers : ExpressionCheckers() { private val _qualifiedAccessExpressionCheckers: MutableSet = mutableSetOf() private val _callCheckers: MutableSet = mutableSetOf() private val _functionCallCheckers: MutableSet = mutableSetOf() + private val _integerLiteralOperatorCallCheckers: MutableSet = mutableSetOf() private val _variableAssignmentCheckers: MutableSet = mutableSetOf() private val _tryExpressionCheckers: MutableSet = mutableSetOf() private val _whenExpressionCheckers: MutableSet = mutableSetOf() @@ -112,6 +115,7 @@ class ComposedExpressionCheckers : ExpressionCheckers() { _qualifiedAccessExpressionCheckers += checkers.qualifiedAccessExpressionCheckers _callCheckers += checkers.callCheckers _functionCallCheckers += checkers.functionCallCheckers + _integerLiteralOperatorCallCheckers += checkers.integerLiteralOperatorCallCheckers _variableAssignmentCheckers += checkers.variableAssignmentCheckers _tryExpressionCheckers += checkers.tryExpressionCheckers _whenExpressionCheckers += checkers.whenExpressionCheckers diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt index 4e0ed573070..c7f5c59fc93 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt @@ -22,6 +22,7 @@ abstract class ExpressionCheckers { open val qualifiedAccessExpressionCheckers: Set = emptySet() open val callCheckers: Set = emptySet() open val functionCallCheckers: Set = emptySet() + open val integerLiteralOperatorCallCheckers: Set = emptySet() open val variableAssignmentCheckers: Set = emptySet() open val tryExpressionCheckers: Set = emptySet() open val whenExpressionCheckers: Set = emptySet() @@ -53,6 +54,7 @@ abstract class ExpressionCheckers { @CheckersComponentInternal internal val allQualifiedAccessExpressionCheckers: Set by lazy { qualifiedAccessExpressionCheckers + basicExpressionCheckers + qualifiedAccessCheckers } @CheckersComponentInternal internal val allCallCheckers: Set by lazy { callCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allFunctionCallCheckers: Set by lazy { functionCallCheckers + qualifiedAccessExpressionCheckers + basicExpressionCheckers + qualifiedAccessCheckers + callCheckers } + @CheckersComponentInternal internal val allIntegerLiteralOperatorCallCheckers: Set by lazy { integerLiteralOperatorCallCheckers + functionCallCheckers + qualifiedAccessExpressionCheckers + basicExpressionCheckers + qualifiedAccessCheckers + callCheckers } @CheckersComponentInternal internal val allVariableAssignmentCheckers: Set by lazy { variableAssignmentCheckers + qualifiedAccessCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allTryExpressionCheckers: Set by lazy { tryExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allWhenExpressionCheckers: Set by lazy { whenExpressionCheckers + basicExpressionCheckers } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt index 0336b553cc6..27dad306628 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirEqualityOperatorCall import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirGetClassCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirLoop import org.jetbrains.kotlin.fir.expressions.FirLoopJump import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess @@ -46,6 +47,7 @@ typealias FirQualifiedAccessChecker = FirExpressionChecker typealias FirQualifiedAccessExpressionChecker = FirExpressionChecker typealias FirCallChecker = FirExpressionChecker typealias FirFunctionCallChecker = FirExpressionChecker +typealias FirIntegerLiteralOperatorCallChecker = FirExpressionChecker typealias FirVariableAssignmentChecker = FirExpressionChecker typealias FirTryExpressionChecker = FirExpressionChecker typealias FirWhenExpressionChecker = FirExpressionChecker diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt index aa316ccde0b..6353c808370 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt @@ -48,6 +48,10 @@ class ExpressionCheckersDiagnosticComponent( checkers.allFunctionCallCheckers.check(functionCall, data, reporter) } + override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: CheckerContext) { + checkers.allIntegerLiteralOperatorCallCheckers.check(integerLiteralOperatorCall, data, reporter) + } + override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: CheckerContext) { checkers.allFunctionCallCheckers.check(implicitInvokeCall, data, reporter) } diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeBuiltinTypeUtils.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeBuiltinTypeUtils.kt index 6f04622f679..fd8ba97a34e 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeBuiltinTypeUtils.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeBuiltinTypeUtils.kt @@ -19,6 +19,9 @@ val ConeKotlinType.isBooleanOrNullableBoolean: Boolean get() = isAnyOfBuiltinTyp val ConeKotlinType.isEnum: Boolean get() = isBuiltinType(StandardClassIds.Enum, false) val ConeKotlinType.isString: Boolean get() = isBuiltinType(StandardClassIds.String, false) val ConeKotlinType.isInt: Boolean get() = isBuiltinType(StandardClassIds.Int, false) +val ConeKotlinType.isLong: Boolean get() = isBuiltinType(StandardClassIds.Long, false) +val ConeKotlinType.isUInt: Boolean get() = isBuiltinType(StandardClassIds.UInt, false) +val ConeKotlinType.isULong: Boolean get() = isBuiltinType(StandardClassIds.ULong, false) val ConeKotlinType.isPrimitiveOrNullablePrimitive: Boolean get() = isAnyOfBuiltinType(StandardClassIds.primitiveTypes) val ConeKotlinType.isPrimitive: Boolean get() = isPrimitiveOrNullablePrimitive && nullability == ConeNullability.NOT_NULL val ConeKotlinType.isArrayType: Boolean diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index 3d1c0bdcd53..61789ce3572 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -78,7 +78,8 @@ class Fir2IrTypeConverter( object : TypeApproximatorConfiguration.AllFlexibleSameValue() { override val allFlexible: Boolean get() = true override val errorType: Boolean get() = true - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true + override val integerConstantOperatorType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmCallConflictResolverFactory.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmCallConflictResolverFactory.kt index 22be8cc18b9..7d66b240fa4 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmCallConflictResolverFactory.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/JvmCallConflictResolverFactory.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls.jvm import org.jetbrains.kotlin.fir.NoMutableState import org.jetbrains.kotlin.fir.resolve.calls.ConeCallConflictResolverFactory import org.jetbrains.kotlin.fir.resolve.calls.ConeCompositeConflictResolver +import org.jetbrains.kotlin.fir.resolve.calls.ConeIntegerOperatorConflictResolver import org.jetbrains.kotlin.fir.resolve.calls.ConeOverloadConflictResolver import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents import org.jetbrains.kotlin.fir.types.typeContext @@ -24,7 +25,8 @@ object JvmCallConflictResolverFactory : ConeCallConflictResolverFactory() { return ConeCompositeConflictResolver( ConeOverloadConflictResolver(specificityComparator, components), ConeEquivalentCallConflictResolver(specificityComparator, components), - JvmPlatformOverloadsConflictResolver(specificityComparator, components) + JvmPlatformOverloadsConflictResolver(specificityComparator, components), + ConeIntegerOperatorConflictResolver(specificityComparator, components) ) } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index d503aaa55f6..0255f4d5ddf 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope import org.jetbrains.kotlin.fir.scopes.impl.FirScopeWithFakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.impl.FirStandardOverrideChecker import org.jetbrains.kotlin.fir.scopes.impl.FirTypeIntersectionScope +import org.jetbrains.kotlin.fir.scopes.impl.getOrBuildScopeForIntegerConstantOperatorType import org.jetbrains.kotlin.fir.scopes.scopeForClass import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl @@ -90,7 +91,8 @@ private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: Scope this ) is ConeDefinitelyNotNullType -> original.scope(useSiteSession, scopeSession, requiredPhase) - is ConeIntegerLiteralType -> error("ILT should not be in receiver position") + is ConeIntegerConstantOperatorType -> scopeSession.getOrBuildScopeForIntegerConstantOperatorType(useSiteSession, this) + is ConeIntegerLiteralConstantType -> error("ILT should not be in receiver position") else -> null } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/ConvertibleIntegerOperators.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/ConvertibleIntegerOperators.kt new file mode 100644 index 00000000000..7ed292307b5 --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/ConvertibleIntegerOperators.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.scopes.impl + +import org.jetbrains.kotlin.name.CallableId +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.name.StandardClassIds + +object ConvertibleIntegerOperators { + val operatorsNames: Set = listOf( + "plus", "minus", "times", "div", "rem", + "and", "or", "xor", + "shl", "shr", "ushr" + ).mapTo(mutableSetOf()) { Name.identifier(it) } +} diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt new file mode 100644 index 00000000000..c617b0a70fd --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt @@ -0,0 +1,158 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.scopes.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.scope +import org.jetbrains.kotlin.fir.resolve.scopeSessionKey +import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor +import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator +import org.jetbrains.kotlin.fir.scopes.FirTypeScope +import org.jetbrains.kotlin.fir.scopes.ProcessorAction +import org.jetbrains.kotlin.fir.scopes.getFunctions +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.fir.symbols.impl.* +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef +import org.jetbrains.kotlin.name.Name +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +class FirIntegerConstantOperatorScope( + val session: FirSession, + val scopeSession: ScopeSession, + val isUnsigned: Boolean +) : FirTypeScope() { + private val baseScope: FirTypeScope = run { + val baseType = when (isUnsigned) { + true -> session.builtinTypes.uIntType + false -> session.builtinTypes.intType + }.type + baseType.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing) ?: error("Scope for $baseType not found") + } + + private val mappedFunctions = mutableMapOf() + + override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) { + if (name !in ConvertibleIntegerOperators.operatorsNames) { + return baseScope.processFunctionsByName(name, processor) + } + val wrappedSymbol = mappedFunctions.getOrPut(name) { + val allFunctions = baseScope.getFunctions(name) + val functionSymbol = allFunctions.first { + val coneType = it.fir.valueParameters.first().returnTypeRef.coneType + if (isUnsigned) { + coneType.isUInt + } else { + coneType.isInt + } + } + wrapIntOperator(functionSymbol) + } + processor(wrappedSymbol) + baseScope.processFunctionsByName(name, processor) + } + + private fun wrapIntOperator(originalSymbol: FirNamedFunctionSymbol): FirNamedFunctionSymbol { + val originalFunction = originalSymbol.fir + val wrappedFunction = buildSimpleFunctionCopy(originalFunction) { + symbol = FirNamedFunctionSymbol(originalSymbol.callableId) + origin = FirDeclarationOrigin.WrappedIntegerOperator + returnTypeRef = buildResolvedTypeRef { + type = ConeIntegerConstantOperatorTypeImpl(isUnsigned, ConeNullability.NOT_NULL) + } + + }.also { + it.originalForWrappedIntegerOperator = originalSymbol + it.isUnsignedWrappedIntegerOperator = isUnsigned + } + return wrappedFunction.symbol + } + + override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) { + baseScope.processPropertiesByName(name, processor) + } + + override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) { + baseScope.processDeclaredConstructors(processor) + } + + override fun mayContainName(name: Name): Boolean { + return baseScope.mayContainName(name) + } + + override fun getCallableNames(): Set { + return baseScope.getCallableNames() + } + + override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) { + // Int types don't have nested classifiers + } + + override fun getClassifierNames(): Set { + return emptySet() + } + + override fun processDirectOverriddenFunctionsWithBaseScope( + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction + ): ProcessorAction { + return ProcessorAction.NONE + } + + override fun processDirectOverriddenPropertiesWithBaseScope( + propertySymbol: FirPropertySymbol, + processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction + ): ProcessorAction { + return ProcessorAction.NONE + } +} + +fun ScopeSession.getOrBuildScopeForIntegerConstantOperatorType( + session: FirSession, + type: ConeIntegerConstantOperatorType +): FirIntegerConstantOperatorScope { + return getOrBuild(type.isUnsigned, INTEGER_CONSTANT_OPERATOR_SCOPE) { + FirIntegerConstantOperatorScope(session, this, type.isUnsigned) + } +} + +private val INTEGER_CONSTANT_OPERATOR_SCOPE = scopeSessionKey() + +private object OriginalForWrappedIntegerOperator : FirDeclarationDataKey() +private object IsUnsignedForWrappedIntegerOperator : FirDeclarationDataKey() + +var FirSimpleFunction.originalForWrappedIntegerOperator: FirNamedFunctionSymbol? by FirDeclarationDataRegistry.data( + OriginalForWrappedIntegerOperator +) + +private var FirSimpleFunction.isUnsignedWrappedIntegerOperator: Boolean? by FirDeclarationDataRegistry.data( + IsUnsignedForWrappedIntegerOperator +) + +@OptIn(ExperimentalContracts::class) +fun FirDeclaration.isWrappedIntegerOperator(): Boolean { + contract { + returns(true) implies (this@isWrappedIntegerOperator is FirSimpleFunction) + } + return (this as? FirSimpleFunction)?.originalForWrappedIntegerOperator != null +} + +@OptIn(ExperimentalContracts::class) +fun FirBasedSymbol<*>.isWrappedIntegerOperator(): Boolean { + contract { + returns(true) implies (this@isWrappedIntegerOperator is FirNamedFunctionSymbol) + } + return fir.isWrappedIntegerOperator() +} + +@OptIn(ExperimentalContracts::class) +fun FirBasedSymbol<*>.isWrappedIntegerOperatorForUnsignedType(): Boolean { + return (this as? FirNamedFunctionSymbol)?.fir?.isUnsignedWrappedIntegerOperator ?: false +} diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index 83303d36a62..7a32117b7e8 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -43,6 +43,14 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty return this is ConeIntegerLiteralType } + override fun TypeConstructorMarker.isIntegerLiteralConstantTypeConstructor(): Boolean { + return this is ConeIntegerLiteralConstantType + } + + override fun TypeConstructorMarker.isIntegerConstantOperatorTypeConstructor(): Boolean { + return this is ConeIntegerConstantOperatorType + } + override fun TypeConstructorMarker.isLocalType(): Boolean { if (this !is ConeClassLikeLookupTag) return false return classId.isLocal diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt index 3ebdbc61216..95c65e04595 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer import org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.transformers.FirSyntheticCallGenerator +import org.jetbrains.kotlin.fir.resolve.transformers.IntegerLiteralAndOperatorApproximationTransformer import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -43,6 +44,7 @@ abstract class BodyResolveComponents : SessionHolder { abstract val syntheticCallGenerator: FirSyntheticCallGenerator abstract val dataFlowAnalyzer: FirDataFlowAnalyzer<*> abstract val outerClassManager: FirOuterClassManager + abstract val integerLiteralAndOperatorApproximationTransformer: IntegerLiteralAndOperatorApproximationTransformer } // --------------------------------------- Utils --------------------------------------- diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 041fdbed3bc..5988e6c180b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -47,8 +47,11 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget +import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.SmartcastStability import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract fun List.toTypeProjections(): Array = asReversed().flatMap { it.typeArgumentList.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray() @@ -485,6 +488,7 @@ fun FirFunction.getAsForbiddenNamedArgumentsTarget(session: FirSession): Forbidd } FirDeclarationOrigin.Synthetic -> null FirDeclarationOrigin.RenamedForOverride -> null + FirDeclarationOrigin.WrappedIntegerOperator -> null is FirDeclarationOrigin.Plugin -> null // TODO: figure out what to do with plugin generated functions } } @@ -493,3 +497,15 @@ fun FirFunction.getAsForbiddenNamedArgumentsTarget(session: FirSession): Forbidd // org.jetbrains.kotlin.fir.serialization.FirElementSerializer.functionProto // org.jetbrains.kotlin.fir.serialization.FirElementSerializer.constructorProto fun FirFunction.getHasStableParameterNames(session: FirSession): Boolean = getAsForbiddenNamedArgumentsTarget(session) == null + +@OptIn(ExperimentalContracts::class) +fun FirExpression?.isIntegerLiteralOrOperatorCall(): Boolean { + contract { + returns(true) implies (this@isIntegerLiteralOrOperatorCall != null) + } + return when (this) { + is FirConstExpression<*> -> kind == ConstantValueKind.Int || kind == ConstantValueKind.IntegerLiteral + is FirIntegerLiteralOperatorCall -> true + else -> false + } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt index ad2e0a56149..a194185ce73 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt @@ -14,8 +14,10 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildErrorProperty import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.moduleData +import org.jetbrains.kotlin.fir.resolve.isIntegerLiteralOrOperatorCall import org.jetbrains.kotlin.fir.returnExpressions import org.jetbrains.kotlin.fir.scopes.FirScope +import org.jetbrains.kotlin.fir.scopes.impl.originalForWrappedIntegerOperator import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.classId @@ -51,6 +53,9 @@ class CandidateFactory private constructor( builtInExtensionFunctionReceiverValue: ReceiverValue? = null, objectsByName: Boolean = false ): Candidate { + @Suppress("NAME_SHADOWING") + val symbol = symbol.unwrapIntegerOperatorSymbolIfNeeded(callInfo) + val result = Candidate( symbol, dispatchReceiverValue, extensionReceiverValue, explicitReceiverKind, context.inferenceComponents.constraintSystemFactory, baseSystem, @@ -87,6 +92,16 @@ class CandidateFactory private constructor( return result } + private fun FirBasedSymbol<*>.unwrapIntegerOperatorSymbolIfNeeded(callInfo: CallInfo): FirBasedSymbol<*> { + if (this !is FirNamedFunctionSymbol) return this + val original = fir.originalForWrappedIntegerOperator ?: return this + return if (callInfo.arguments.first().isIntegerLiteralOrOperatorCall()) { + this + } else { + original + } + } + private fun ReceiverValue?.isCandidateFromCompanionObjectTypeScope(): Boolean { val expressionReceiverValue = this as? ExpressionReceiverValue ?: return false val resolvedQualifier = (expressionReceiverValue.explicitReceiver as? FirResolvedQualifier) ?: return false diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeIntegerOperatorConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeIntegerOperatorConflictResolver.kt new file mode 100644 index 00000000000..ae81b7b7efc --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeIntegerOperatorConflictResolver.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.resolve.calls + +import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents +import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperator +import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator + +class ConeIntegerOperatorConflictResolver( + specificityComparator: TypeSpecificityComparator, + inferenceComponents: InferenceComponents +) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents) { + override fun chooseMaximallySpecificCandidates( + candidates: Set, + discriminateGenerics: Boolean, + discriminateAbstracts: Boolean + ): Set { + if (candidates.size <= 1) { + return candidates + } + val candidateWithWrappedIntegerOperator = candidates.firstOrNull { it.symbol.isWrappedIntegerOperator() } + return if (candidateWithWrappedIntegerOperator != null) { + setOf(candidateWithWrappedIntegerOperator) + } else { + candidates + } + } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt index 407d5f8db5a..edef27fe732 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt @@ -29,7 +29,7 @@ fun Candidate.computeCompletionMode( expectedType != null -> ConstraintSystemCompletionMode.FULL // This is questionable as null return type can be only for error call - currentReturnType == null || currentReturnType is ConeIntegerLiteralType -> ConstraintSystemCompletionMode.PARTIAL + currentReturnType == null -> ConstraintSystemCompletionMode.PARTIAL // Full if return type for call has no type variables csBuilder.isProperType(currentReturnType) -> ConstraintSystemCompletionMode.FULL diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt index 243c231d75b..40c5d8a0b98 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt @@ -123,9 +123,11 @@ class FirCallCompleter( .buildAbstractResultingSubstitutor(session.typeContext) as ConeSubstitutor val completedCall = call.transformSingle( FirCallCompletionResultsWriterTransformer( - session, finalSubstitutor, components.returnTypeCalculator, + session, finalSubstitutor, + components.returnTypeCalculator, session.typeApproximator, components.dataFlowAnalyzer, + components.integerLiteralAndOperatorApproximationTransformer ), null ) @@ -236,6 +238,7 @@ class FirCallCompleter( session, substitutor, components.returnTypeCalculator, session.typeApproximator, components.dataFlowAnalyzer, + components.integerLiteralAndOperatorApproximationTransformer, mode ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index ed683db5d65..8928cf2c19c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -41,6 +41,8 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCall import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.remapArgumentsWithVararg import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.writeResultType +import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperator +import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperatorForUnsignedType import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol @@ -68,6 +70,7 @@ class FirCallCompletionResultsWriterTransformer( private val typeCalculator: ReturnTypeCalculator, private val typeApproximator: ConeTypeApproximator, private val dataFlowAnalyzer: FirDataFlowAnalyzer<*>, + private val integerOperatorApproximator: IntegerLiteralAndOperatorApproximationTransformer, private val mode: Mode = Mode.Normal ) : FirAbstractTreeTransformer(phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) { @@ -126,14 +129,23 @@ class FirCallCompletionResultsWriterTransformer( } } + var dispatchReceiver = subCandidate.dispatchReceiverExpression() + var extensionReceiver = subCandidate.extensionReceiverExpression() + if (!declaration.isWrappedIntegerOperator()) { + val expectedDispatchReceiverType = (declaration as? FirCallableDeclaration)?.dispatchReceiverType + val expectedExtensionReceiverType = (declaration as? FirCallableDeclaration)?.receiverTypeRef?.coneType + dispatchReceiver = dispatchReceiver.transformSingle(integerOperatorApproximator, expectedDispatchReceiverType) + extensionReceiver = extensionReceiver.transformSingle(integerOperatorApproximator, expectedExtensionReceiverType) + } + @Suppress("UNCHECKED_CAST") val result = qualifiedAccessExpression .transformCalleeReference( StoreCalleeReference, calleeReference.toResolvedReference(), ) - .transformDispatchReceiver(StoreReceiver, subCandidate.dispatchReceiverExpression()) - .transformExtensionReceiver(StoreReceiver, subCandidate.extensionReceiverExpression()) as T + .transformDispatchReceiver(StoreReceiver, dispatchReceiver) + .transformExtensionReceiver(StoreReceiver, extensionReceiver) as T if (result is FirPropertyAccessExpressionImpl && calleeReference.candidate.currentApplicability == CandidateApplicability.PROPERTY_AS_OPERATOR) { result.nonFatalDiagnostics.add(ConePropertyAsOperator(calleeReference.candidate.symbol as FirPropertySymbol)) } @@ -199,8 +211,6 @@ class FirCallCompletionResultsWriterTransformer( val subCandidate = calleeReference.candidate val resultType: FirTypeRef resultType = typeRef.substituteTypeRef(subCandidate) - val expectedArgumentsTypeMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() } - result.argumentList.transformArguments(this, expectedArgumentsTypeMapping) if (calleeReference.isError) { subCandidate.argumentMapping?.let { result.replaceArgumentList(buildArgumentListForErrorCall(result.argumentList, it)) @@ -225,6 +235,8 @@ class FirCallCompletionResultsWriterTransformer( result.replaceArgumentList(newArgumentList) } } + val expectedArgumentsTypeMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() } + result.argumentList.transformArguments(this, expectedArgumentsTypeMapping) result.replaceTypeRef(resultType) session.lookupTracker?.recordTypeResolveAsLookup(resultType, functionCall.source, null) @@ -445,12 +457,18 @@ class FirCallCompletionResultsWriterTransformer( Pair(it.atom, finalSubstitutor.substituteOrSelf(substitutor.substituteOrSelf(it.returnType))) } + val isIntegerOperator = symbol.isWrappedIntegerOperator() + val arguments = argumentMapping?.map { (argument, valueParameter) -> - val expectedType = if (valueParameter.isVararg) { - valueParameter.returnTypeRef.substitute(this).varargElementType() - } else { - valueParameter.returnTypeRef.substitute(this) + val expectedType = when { + isIntegerOperator -> ConeIntegerConstantOperatorTypeImpl( + isUnsigned = symbol.isWrappedIntegerOperatorForUnsignedType(), + ConeNullability.NOT_NULL + ) + valueParameter.isVararg -> valueParameter.returnTypeRef.substitute(this).varargElementType() + else -> valueParameter.returnTypeRef.substitute(this) } + val unwrappedArgument: FirElement = when (val unwrappedArgument = argument.unwrapArgument()) { is FirAnonymousFunctionExpression -> unwrappedArgument.anonymousFunction else -> unwrappedArgument @@ -781,7 +799,23 @@ class FirCallCompletionResultsWriterTransformer( data: ExpectedArgumentType?, ): FirStatement { if (data == ExpectedArgumentType.NoApproximation) return constExpression - return constExpression.approximateIfIsIntegerConst(data?.getExpectedType(constExpression)) + val expectedType = data?.getExpectedType(constExpression) + if (expectedType is ConeIntegerConstantOperatorType) { + return constExpression + } + return constExpression.transformSingle(integerOperatorApproximator, expectedType) + } + + override fun transformIntegerLiteralOperatorCall( + integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, + data: ExpectedArgumentType? + ): FirStatement { + if (data == ExpectedArgumentType.NoApproximation) return integerLiteralOperatorCall + val expectedType = data?.getExpectedType(integerLiteralOperatorCall) + if (expectedType is ConeIntegerConstantOperatorType) { + return integerLiteralOperatorCall + } + return integerLiteralOperatorCall.transformSingle(integerOperatorApproximator, expectedType) } override fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: ExpectedArgumentType?): FirStatement { @@ -800,6 +834,15 @@ class FirCallCompletionResultsWriterTransformer( return arrayOfCall } + override fun transformVarargArgumentsExpression( + varargArgumentsExpression: FirVarargArgumentsExpression, + data: ExpectedArgumentType? + ): FirStatement { + val expectedType = data?.getExpectedType(varargArgumentsExpression)?.let { ExpectedArgumentType.ExpectedType(it) } + varargArgumentsExpression.transformChildren(this, expectedType) + return varargArgumentsExpression + } + private fun FirNamedReferenceWithCandidate.toResolvedReference(): FirNamedReference { val errorDiagnostic = when { this is FirErrorReferenceWithCandidate -> this.diagnostic diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt new file mode 100644 index 00000000000..c50e389b5f5 --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt @@ -0,0 +1,126 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.resolve.transformers + +import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.fakeElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirConstExpression +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall +import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.expressions.builder.buildFunctionCall +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference +import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference +import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.scope +import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType +import org.jetbrains.kotlin.fir.resolvedSymbol +import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype +import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator +import org.jetbrains.kotlin.fir.scopes.getFunctions +import org.jetbrains.kotlin.fir.scopes.impl.originalForWrappedIntegerOperator +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef +import org.jetbrains.kotlin.fir.visitors.FirTransformer +import org.jetbrains.kotlin.fir.visitors.transformSingle +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.ConstantValueKind + +fun IntegerLiteralAndOperatorApproximationTransformer.approximateIfIsIntegerConst(expression: FirExpression, expectedType: ConeKotlinType? = null): FirExpression { + return expression.transformSingle(this, expectedType) +} + +class IntegerLiteralAndOperatorApproximationTransformer( + val session: FirSession, + val scopeSession: ScopeSession +) : FirTransformer() { + companion object { + private val TO_LONG = Name.identifier("toLong") + private val TO_U_LONG = Name.identifier("toULong") + } + + private val toLongSymbol by lazy { findConversionFunction(session.builtinTypes.intType, TO_LONG)} + private val toULongSymbol by lazy { findConversionFunction(session.builtinTypes.uIntType, TO_U_LONG)} + + private fun findConversionFunction(receiverType: FirImplicitBuiltinTypeRef, name: Name): FirNamedFunctionSymbol { + return receiverType.type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing)!!.getFunctions(name).single() + } + + override fun transformElement(element: E, data: ConeKotlinType?): E { + return element + } + + override fun transformConstExpression( + constExpression: FirConstExpression, + data: ConeKotlinType? + ): FirStatement { + val type = constExpression.resultType.coneTypeSafe() ?: return constExpression + val approximatedType = type.getApproximatedType(data) + constExpression.resultType = constExpression.resultType.resolvedTypeFromPrototype(approximatedType) + @Suppress("UNCHECKED_CAST") + val kind = approximatedType.toConstKind() as ConstantValueKind + constExpression.replaceKind(kind) + return constExpression + } + + override fun transformIntegerLiteralOperatorCall( + integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, + data: ConeKotlinType? + ): FirStatement { + @Suppress("UnnecessaryVariable") + val call = integerLiteralOperatorCall + val operatorType = call.resultType.coneTypeSafe() ?: return call + val approximatedType = operatorType.getApproximatedType(data) + call.transformDispatchReceiver(this, null) + call.transformExtensionReceiver(this, null) + call.argumentList.transformArguments(this, null) + + call.resultType = call.resultType.resolvedTypeFromPrototype(approximatedType) + + val calleeReference = call.calleeReference + // callee reference may also be an error reference and it's ok if wrapped operator function leaks throw it + if (calleeReference is FirResolvedNamedReference) { + val wrappedFunctionSymbol = calleeReference.resolvedSymbol as FirNamedFunctionSymbol + val originalFunctionSymbol = wrappedFunctionSymbol.fir.originalForWrappedIntegerOperator!! + + call.replaceCalleeReference( + buildResolvedNamedReference { + name = calleeReference.name + source = calleeReference.source + resolvedSymbol = originalFunctionSymbol + } + ) + } + + if (approximatedType.isInt || approximatedType.isUInt) return call + val typeBeforeConversion = if (operatorType.isUnsigned) { + session.builtinTypes.uIntType + } else { + session.builtinTypes.intType + } + call.replaceTypeRef(typeBeforeConversion) + + return buildFunctionCall { + source = call.source?.fakeElement(KtFakeSourceElementKind.IntToLongConversion) + typeRef = session.builtinTypes.longType + explicitReceiver = call + dispatchReceiver = call + this.calleeReference = buildResolvedNamedReference { + if (operatorType.isUnsigned) { + name = TO_U_LONG + resolvedSymbol = toULongSymbol + } else { + name = TO_LONG + resolvedSymbol = toLongSymbol + } + } + } + } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt deleted file mode 100644 index 24670c8ef8b..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.fir.resolve.transformers - -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.expressions.FirConstExpression -import org.jetbrains.kotlin.fir.expressions.FirExpression -import org.jetbrains.kotlin.fir.expressions.FirStatement -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType -import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype -import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralType -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.coneTypeSafe -import org.jetbrains.kotlin.fir.types.toConstKind -import org.jetbrains.kotlin.fir.visitors.FirTransformer -import org.jetbrains.kotlin.fir.visitors.transformSingle -import org.jetbrains.kotlin.types.ConstantValueKind - -fun FirExpression.approximateIfIsIntegerConst(expectedType: ConeKotlinType? = null): FirExpression { - return transformSingle(IntegerLiteralTypeApproximationTransformer, expectedType) -} - -private object IntegerLiteralTypeApproximationTransformer : FirTransformer() { - override fun transformElement(element: E, data: ConeKotlinType?): E { - return element - } - - override fun transformConstExpression( - constExpression: FirConstExpression, - data: ConeKotlinType? - ): FirStatement { - val type = constExpression.resultType.coneTypeSafe() ?: return constExpression - val approximatedType = type.getApproximatedType(data) - constExpression.resultType = constExpression.resultType.resolvedTypeFromPrototype(approximatedType) - @Suppress("UNCHECKED_CAST") - val kind = approximatedType.toConstKind() as ConstantValueKind - constExpression.replaceKind(kind) - return constExpression - } -} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt index 05074d9e688..01dc1417bad 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt @@ -18,10 +18,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider -import org.jetbrains.kotlin.fir.resolve.transformers.FirAbstractPhaseTransformer -import org.jetbrains.kotlin.fir.resolve.transformers.FirSpecificTypeResolverTransformer -import org.jetbrains.kotlin.fir.resolve.transformers.FirSyntheticCallGenerator -import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator +import org.jetbrains.kotlin.fir.resolve.transformers.* import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -112,5 +109,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb override val doubleColonExpressionResolver: FirDoubleColonExpressionResolver = FirDoubleColonExpressionResolver(session) override val outerClassManager: FirOuterClassManager = FirOuterClassManager(session, context.outerLocalClassForNested) override val samResolver: FirSamResolver = FirSamResolverImpl(session, scopeSession, outerClassManager) + override val integerLiteralAndOperatorApproximationTransformer: IntegerLiteralAndOperatorApproximationTransformer = + IntegerLiteralAndOperatorApproximationTransformer(session, scopeSession) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index d0a2610d8cd..64f092cd58e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -305,8 +305,8 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor ): FirStatement { dataFlowAnalyzer.enterDelegateExpression() // First, resolve delegate expression in dependent context - val delegateExpression = - wrappedDelegateExpression.expression.transformSingle(transformer, ResolutionMode.ContextDependent) + val delegateExpression = wrappedDelegateExpression.expression.transformSingle(transformer, ResolutionMode.ContextDependent) + .transformSingle(components.integerLiteralAndOperatorApproximationTransformer, null) // Second, replace result type of delegate expression with stub type if delegate not yet resolved if (delegateExpression is FirQualifiedAccess) { @@ -355,7 +355,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor // Select delegate expression otherwise return delegateExpression - .approximateIfIsIntegerConst() } private fun transformLocalVariable(variable: FirProperty): FirProperty { @@ -826,6 +825,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor components.returnTypeCalculator, session.typeApproximator, dataFlowAnalyzer, + components.integerLiteralAndOperatorApproximationTransformer ) lambda.transformSingle(writer, expectedTypeRef.coneTypeSafe()?.toExpectedType()) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index b329f333a4f..aa2ec01c7bd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -23,12 +23,15 @@ import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.* +import org.jetbrains.kotlin.fir.resolve.dfa.coneType import org.jetbrains.kotlin.fir.resolve.dfa.unwrapSmartcastExpression import org.jetbrains.kotlin.fir.resolve.diagnostics.* import org.jetbrains.kotlin.fir.resolve.inference.FirStubInferenceSession import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.InvocationKindTransformer import org.jetbrains.kotlin.fir.resolve.transformers.StoreReceiver +import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperator +import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperatorForUnsignedType import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef @@ -373,14 +376,58 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform } catch (e: Throwable) { throw RuntimeException("While resolving call ${functionCall.render()}", e) } - - dataFlowAnalyzer.exitFunctionCall(completeInference, callCompleted) + val result = completeInference.transformToIntegerOperatorCallOrApproximateItIfNeeded(data) + dataFlowAnalyzer.exitFunctionCall(result, callCompleted) if (callCompleted) { if (enableArrayOfCallTransformation) { - return arrayOfCallTransformer.transformFunctionCall(completeInference, null) + return arrayOfCallTransformer.transformFunctionCall(result, null) } } - return completeInference + return result + } + + private fun FirFunctionCall.transformToIntegerOperatorCallOrApproximateItIfNeeded(resolutionMode: ResolutionMode): FirFunctionCall { + if (!explicitReceiver.isIntegerLiteralOrOperatorCall()) return this + val resolvedSymbol = when (val reference = calleeReference) { + is FirResolvedNamedReference -> reference.resolvedSymbol + is FirErrorNamedReference -> reference.candidateSymbol + else -> null + } ?: return this + if (!resolvedSymbol.isWrappedIntegerOperator()) return this + + val argument = this.argumentList.arguments.singleOrNull() ?: return this + assert(argument.isIntegerLiteralOrOperatorCall()) + + val originalCall = this + + val integerOperatorType = ConeIntegerConstantOperatorTypeImpl( + isUnsigned = resolvedSymbol.isWrappedIntegerOperatorForUnsignedType(), + ConeNullability.NOT_NULL + ) + + val approximationIsNeeded = resolutionMode !is ResolutionMode.ReceiverResolution && resolutionMode !is ResolutionMode.ContextDependent + + val integerOperatorCall = buildIntegerLiteralOperatorCall { + source = originalCall.source + typeRef = originalCall.typeRef.resolvedTypeFromPrototype(integerOperatorType) + annotations.addAll(originalCall.annotations) + typeArguments.addAll(originalCall.typeArguments) + calleeReference = originalCall.calleeReference + origin = originalCall.origin + argumentList = originalCall.argumentList + explicitReceiver = originalCall.explicitReceiver + dispatchReceiver = originalCall.dispatchReceiver + extensionReceiver = originalCall.extensionReceiver + } + + return if (approximationIsNeeded) { + integerOperatorCall.transformSingle( + components.integerLiteralAndOperatorApproximationTransformer, + resolutionMode.expectedType?.coneTypeSafe() + ) + } else { + integerOperatorCall + } } override fun transformBlock(block: FirBlock, data: ResolutionMode): FirStatement { @@ -917,6 +964,10 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform constExpression.replaceKind(expressionType.toConstKind() as ConstantValueKind) expressionType } + data is ResolutionMode.ReceiverResolution -> { + require(expressionType is ConeIntegerLiteralConstantTypeImpl) + ConeIntegerConstantOperatorTypeImpl(expressionType.isUnsigned, ConeNullability.NOT_NULL) + } expectedTypeRef != null -> { require(expressionType is ConeIntegerLiteralConstantTypeImpl) val coneType = expectedTypeRef.coneTypeSafe()?.fullyExpandedType(session) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirIntegerLiteralOperatorCall.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirIntegerLiteralOperatorCall.kt new file mode 100644 index 00000000000..7be52ec4ea4 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirIntegerLiteralOperatorCall.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.references.FirNamedReference +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* +import org.jetbrains.kotlin.fir.FirImplementationDetail + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +abstract class FirIntegerLiteralOperatorCall : FirFunctionCall() { + abstract override val source: KtSourceElement? + abstract override val typeRef: FirTypeRef + abstract override val annotations: List + abstract override val typeArguments: List + abstract override val explicitReceiver: FirExpression? + abstract override val dispatchReceiver: FirExpression + abstract override val extensionReceiver: FirExpression + abstract override val argumentList: FirArgumentList + abstract override val calleeReference: FirNamedReference + abstract override val origin: FirFunctionCallOrigin + + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitIntegerLiteralOperatorCall(this, data) + + @Suppress("UNCHECKED_CAST") + override fun transform(transformer: FirTransformer, data: D): E = + transformer.transformIntegerLiteralOperatorCall(this, data) as E + + @FirImplementationDetail + abstract override fun replaceSource(newSource: KtSourceElement?) + + abstract override fun replaceTypeRef(newTypeRef: FirTypeRef) + + abstract override fun replaceTypeArguments(newTypeArguments: List) + + abstract override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?) + + abstract override fun replaceArgumentList(newArgumentList: FirArgumentList) + + abstract override fun replaceCalleeReference(newCalleeReference: FirNamedReference) + + abstract override fun replaceCalleeReference(newCalleeReference: FirReference) + + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall + + abstract override fun transformTypeArguments(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall + + abstract override fun transformExplicitReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall + + abstract override fun transformDispatchReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall + + abstract override fun transformExtensionReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall + + abstract override fun transformCalleeReference(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCall +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirIntegerLiteralOperatorCallBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirIntegerLiteralOperatorCallBuilder.kt new file mode 100644 index 00000000000..df44de915ee --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirIntegerLiteralOperatorCallBuilder.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions.builder + +import kotlin.contracts.* +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.FirImplementationDetail +import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder +import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.expressions.FirArgumentList +import org.jetbrains.kotlin.fir.expressions.FirEmptyArgumentList +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall +import org.jetbrains.kotlin.fir.expressions.builder.FirAbstractFunctionCallBuilder +import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder +import org.jetbrains.kotlin.fir.expressions.impl.FirIntegerLiteralOperatorCallImpl +import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression +import org.jetbrains.kotlin.fir.references.FirNamedReference +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +@FirBuilderDsl +open class FirIntegerLiteralOperatorCallBuilder : FirAbstractFunctionCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder { + override var source: KtSourceElement? = null + override lateinit var typeRef: FirTypeRef + override val annotations: MutableList = mutableListOf() + override val typeArguments: MutableList = mutableListOf() + override var explicitReceiver: FirExpression? = null + override var dispatchReceiver: FirExpression = FirNoReceiverExpression + override var extensionReceiver: FirExpression = FirNoReceiverExpression + override var argumentList: FirArgumentList = FirEmptyArgumentList + override lateinit var calleeReference: FirNamedReference + override lateinit var origin: FirFunctionCallOrigin + + override fun build(): FirIntegerLiteralOperatorCall { + return FirIntegerLiteralOperatorCallImpl( + source, + typeRef, + annotations, + typeArguments, + explicitReceiver, + dispatchReceiver, + extensionReceiver, + argumentList, + calleeReference, + origin, + ) + } + +} + +@OptIn(ExperimentalContracts::class) +inline fun buildIntegerLiteralOperatorCall(init: FirIntegerLiteralOperatorCallBuilder.() -> Unit): FirIntegerLiteralOperatorCall { + contract { + callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE) + } + return FirIntegerLiteralOperatorCallBuilder().apply(init).build() +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirIntegerLiteralOperatorCallImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirIntegerLiteralOperatorCallImpl.kt new file mode 100644 index 00000000000..7f9b1ac984f --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirIntegerLiteralOperatorCallImpl.kt @@ -0,0 +1,129 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions.impl + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.expressions.FirArgumentList +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall +import org.jetbrains.kotlin.fir.references.FirNamedReference +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* +import org.jetbrains.kotlin.fir.FirImplementationDetail + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +internal class FirIntegerLiteralOperatorCallImpl( + override var source: KtSourceElement?, + override var typeRef: FirTypeRef, + override val annotations: MutableList, + override val typeArguments: MutableList, + override var explicitReceiver: FirExpression?, + override var dispatchReceiver: FirExpression, + override var extensionReceiver: FirExpression, + override var argumentList: FirArgumentList, + override var calleeReference: FirNamedReference, + override val origin: FirFunctionCallOrigin, +) : FirIntegerLiteralOperatorCall() { + override fun acceptChildren(visitor: FirVisitor, data: D) { + typeRef.accept(visitor, data) + annotations.forEach { it.accept(visitor, data) } + typeArguments.forEach { it.accept(visitor, data) } + explicitReceiver?.accept(visitor, data) + if (dispatchReceiver !== explicitReceiver) { + dispatchReceiver.accept(visitor, data) + } + if (extensionReceiver !== explicitReceiver && extensionReceiver !== dispatchReceiver) { + extensionReceiver.accept(visitor, data) + } + argumentList.accept(visitor, data) + calleeReference.accept(visitor, data) + } + + override fun transformChildren(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + typeRef = typeRef.transform(transformer, data) + transformAnnotations(transformer, data) + transformTypeArguments(transformer, data) + explicitReceiver = explicitReceiver?.transform(transformer, data) + if (dispatchReceiver !== explicitReceiver) { + dispatchReceiver = dispatchReceiver.transform(transformer, data) + } + if (extensionReceiver !== explicitReceiver && extensionReceiver !== dispatchReceiver) { + extensionReceiver = extensionReceiver.transform(transformer, data) + } + argumentList = argumentList.transform(transformer, data) + transformCalleeReference(transformer, data) + return this + } + + override fun transformAnnotations(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + annotations.transformInplace(transformer, data) + return this + } + + override fun transformTypeArguments(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + typeArguments.transformInplace(transformer, data) + return this + } + + override fun transformExplicitReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + explicitReceiver = explicitReceiver?.transform(transformer, data) + return this + } + + override fun transformDispatchReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + dispatchReceiver = dispatchReceiver.transform(transformer, data) + return this + } + + override fun transformExtensionReceiver(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + extensionReceiver = extensionReceiver.transform(transformer, data) + return this + } + + override fun transformCalleeReference(transformer: FirTransformer, data: D): FirIntegerLiteralOperatorCallImpl { + calleeReference = calleeReference.transform(transformer, data) + return this + } + + @FirImplementationDetail + override fun replaceSource(newSource: KtSourceElement?) { + source = newSource + } + + override fun replaceTypeRef(newTypeRef: FirTypeRef) { + typeRef = newTypeRef + } + + override fun replaceTypeArguments(newTypeArguments: List) { + typeArguments.clear() + typeArguments.addAll(newTypeArguments) + } + + override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?) { + explicitReceiver = newExplicitReceiver + } + + override fun replaceArgumentList(newArgumentList: FirArgumentList) { + argumentList = newArgumentList + } + + override fun replaceCalleeReference(newCalleeReference: FirNamedReference) { + calleeReference = newCalleeReference + } + + override fun replaceCalleeReference(newCalleeReference: FirReference) { + require(newCalleeReference is FirNamedReference) + replaceCalleeReference(newCalleeReference) + } +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt index 0909ddc3b01..4c94e1d14b6 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt @@ -91,6 +91,7 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorProperty import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall @@ -213,6 +214,8 @@ abstract class FirDefaultVisitor : FirVisitor() { override fun visitPropertyAccessExpression(propertyAccessExpression: FirPropertyAccessExpression, data: D): R = visitQualifiedAccessExpression(propertyAccessExpression, data) + override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: D): R = visitFunctionCall(integerLiteralOperatorCall, data) + override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: D): R = visitFunctionCall(implicitInvokeCall, data) override fun visitComponentCall(componentCall: FirComponentCall, data: D): R = visitFunctionCall(componentCall, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt index 5d3a8298bec..71d273dd860 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt @@ -91,6 +91,7 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorProperty import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall @@ -213,6 +214,8 @@ abstract class FirDefaultVisitorVoid : FirVisitorVoid() { override fun visitPropertyAccessExpression(propertyAccessExpression: FirPropertyAccessExpression) = visitQualifiedAccessExpression(propertyAccessExpression) + override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall) = visitFunctionCall(integerLiteralOperatorCall) + override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall) = visitFunctionCall(implicitInvokeCall) override fun visitComponentCall(componentCall: FirComponentCall) = visitFunctionCall(componentCall) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt index 5def54f3dde..e9ba371ead5 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt @@ -91,6 +91,7 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorProperty import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall @@ -492,6 +493,10 @@ abstract class FirTransformer : FirVisitor() { return transformElement(functionCall, data) } + open fun transformIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: D): FirStatement { + return transformElement(integerLiteralOperatorCall, data) + } + open fun transformImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: D): FirStatement { return transformElement(implicitInvokeCall, data) } @@ -1040,6 +1045,10 @@ abstract class FirTransformer : FirVisitor() { return transformFunctionCall(functionCall, data) } + final override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: D): FirStatement { + return transformIntegerLiteralOperatorCall(integerLiteralOperatorCall, data) + } + final override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: D): FirStatement { return transformImplicitInvokeCall(implicitInvokeCall, data) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt index cd288e675dd..76b7e549c2d 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt @@ -91,6 +91,7 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorProperty import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall @@ -321,6 +322,8 @@ abstract class FirVisitor { open fun visitFunctionCall(functionCall: FirFunctionCall, data: D): R = visitElement(functionCall, data) + open fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: D): R = visitElement(integerLiteralOperatorCall, data) + open fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: D): R = visitElement(implicitInvokeCall, data) open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): R = visitElement(delegatedConstructorCall, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt index fb99d944cfe..e626e20dc5a 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt @@ -91,6 +91,7 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorProperty import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall @@ -491,6 +492,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitElement(functionCall) } + open fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall) { + visitElement(integerLiteralOperatorCall) + } + open fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall) { visitElement(implicitInvokeCall) } @@ -1039,6 +1044,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitFunctionCall(functionCall) } + final override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall, data: Nothing?) { + visitIntegerLiteralOperatorCall(integerLiteralOperatorCall) + } + final override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall, data: Nothing?) { visitImplicitInvokeCall(implicitInvokeCall) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 962c37a6c95..7649e1b26ae 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -1321,6 +1321,10 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode = visitCall(functionCall) } + override fun visitIntegerLiteralOperatorCall(integerLiteralOperatorCall: FirIntegerLiteralOperatorCall) { + visitFunctionCall(integerLiteralOperatorCall) + } + override fun visitImplicitInvokeCall(implicitInvokeCall: FirImplicitInvokeCall) { visitFunctionCall(implicitInvokeCall) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSession.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSession.kt index 8283546d468..a4fb13a5d08 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSession.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSession.kt @@ -65,6 +65,10 @@ class BuiltinTypes { val longType: FirImplicitBuiltinTypeRef = FirImplicitLongTypeRef(null) val doubleType: FirImplicitBuiltinTypeRef = FirImplicitDoubleTypeRef(null) val floatType: FirImplicitBuiltinTypeRef = FirImplicitFloatTypeRef(null) + + val uIntType: FirImplicitUIntTypeRef = FirImplicitUIntTypeRef(null) + val uLongType: FirImplicitULongTypeRef = FirImplicitULongTypeRef(null) + val nothingType: FirImplicitBuiltinTypeRef = FirImplicitNothingTypeRef(null) val nullableNothingType: FirImplicitBuiltinTypeRef = FirImplicitNullableNothingTypeRef(null) val charType: FirImplicitBuiltinTypeRef = FirImplicitCharTypeRef(null) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationOrigin.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationOrigin.kt index ab739c3da96..37e3189c889 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationOrigin.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationOrigin.kt @@ -19,6 +19,7 @@ sealed class FirDeclarationOrigin(private val displayName: String? = null, val f object IntersectionOverride : FirDeclarationOrigin(fromSupertypes = true) object Delegated : FirDeclarationOrigin() object RenamedForOverride : FirDeclarationOrigin() + object WrappedIntegerOperator : FirDeclarationOrigin() class Plugin(val key: FirPluginKey) : FirDeclarationOrigin(displayName = "Plugin[$key]", generated = true) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt index 0ef2fce34fc..83f7ccf52a7 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.approxima import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.createClassLikeType import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.createSupertypeList import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.getApproximatedTypeImpl -import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.withNullability +import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeExtensions.withNullabilityAndAttributes import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.types.AbstractTypeChecker @@ -68,7 +68,7 @@ class ConeIntegerLiteralConstantTypeImpl( addSignedPossibleTypes() } return if (possibleTypes.size == 1) { - possibleTypes.single().withNullability(nullability).also { + possibleTypes.single().withNullabilityAndAttributes(nullability, ConeAttributes.Empty).also { if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) { assert(it.isLong() || it.isULong()) } @@ -149,12 +149,12 @@ private object ConeIntegerLiteralTypeExtensions { fun ConeIntegerLiteralType.getApproximatedTypeImpl(expectedType: ConeKotlinType?): ConeClassLikeType { val expectedTypeForApproximation = (expectedType?.lowerBoundIfFlexible() as? ConeClassLikeType) - ?.withNullability(ConeNullability.NOT_NULL) + ?.withNullabilityAndAttributes(ConeNullability.NOT_NULL, ConeAttributes.Empty) val approximatedType = when (expectedTypeForApproximation) { null, !in possibleTypes -> possibleTypes.first() else -> expectedTypeForApproximation } - return approximatedType.withNullability(nullability) + return approximatedType.withNullabilityAndAttributes(nullability, attributes) } @@ -218,12 +218,12 @@ private object ConeIntegerLiteralTypeExtensions { return this } - fun ConeClassLikeType.withNullability(nullability: ConeNullability): ConeClassLikeType { - if (nullability == this.nullability) return this + fun ConeClassLikeType.withNullabilityAndAttributes(nullability: ConeNullability, attributes: ConeAttributes): ConeClassLikeType { + if (nullability == this.nullability && attributes == this.attributes) return this return when (this) { is ConeErrorType -> this - is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable) + is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes) else -> error("sealed") } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt index f7b4c6fbba9..c32591001c5 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt @@ -93,6 +93,14 @@ class FirImplicitFloatTypeRef( source: KtSourceElement? ) : FirImplicitBuiltinTypeRef(source, StandardClassIds.Float) +class FirImplicitUIntTypeRef( + source: KtSourceElement? +) : FirImplicitBuiltinTypeRef(source, StandardClassIds.UInt) + +class FirImplicitULongTypeRef( + source: KtSourceElement? +) : FirImplicitBuiltinTypeRef(source, StandardClassIds.ULong) + class FirImplicitNothingTypeRef( source: KtSourceElement? ) : FirImplicitBuiltinTypeRef(source, StandardClassIds.Nothing) @@ -177,6 +185,8 @@ fun FirImplicitBuiltinTypeRef.withFakeSource(kind: KtFakeSourceElementKind): Fir is FirImplicitLongTypeRef -> FirImplicitLongTypeRef(newSource) is FirImplicitDoubleTypeRef -> FirImplicitDoubleTypeRef(newSource) is FirImplicitFloatTypeRef -> FirImplicitFloatTypeRef(newSource) + is FirImplicitUIntTypeRef -> FirImplicitUIntTypeRef(newSource) + is FirImplicitULongTypeRef -> FirImplicitULongTypeRef(newSource) is FirImplicitNothingTypeRef -> FirImplicitNothingTypeRef(newSource) is FirImplicitNullableNothingTypeRef -> FirImplicitNullableNothingTypeRef(newSource) is FirImplicitCharTypeRef -> FirImplicitCharTypeRef(newSource) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index b38c9f0b3c4..d61daffe4d7 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -192,6 +192,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree value = "FirFunctionCallOrigin.Regular" } } + builder(integerLiteralOperatorCall, init = configurationForFunctionCallBuilder) builder(implicitInvokeCall, init = configurationForFunctionCallBuilder) builder(getClassCall) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt index f16fb8ffcae..98fa81b370c 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt @@ -111,6 +111,7 @@ object FirTreeBuilder : AbstractFirTreeBuilder() { val qualifiedAccessExpression by element(Expression, expression, qualifiedAccess) val propertyAccessExpression by element(Expression, qualifiedAccessExpression) val functionCall by element(Expression, qualifiedAccessExpression, call) + val integerLiteralOperatorCall by element(Expression, functionCall) val implicitInvokeCall by element(Expression, functionCall) val delegatedConstructorCall by element(Expression, resolvable, call) val componentCall by element(Expression, functionCall) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 891e044036c..722a02ef84e 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -560,6 +560,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() "FirSafeCallExpressionImpl", "FirCheckedSafeCallSubjectImpl", "FirArrayOfCallImpl", + "FirIntegerLiteralOperatorCallImpl" ) configureFieldInAllImplementations( field = "typeRef", diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt index 9fd69b8d64c..63e0fe1c99f 100644 --- a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt @@ -188,6 +188,10 @@ sealed class KtFakeSourceElementKind : KtSourceElementKind() { // with a fake source that refers to the value parameter in the function type notation // e.g., `(x: Int) -> Unit` becomes `Function1<@ParameterName("x") Int, Unit>` object ParameterNameAnnotationCall : KtFakeSourceElementKind() + + // for implicit conversion from int to long with `.toLong` function + // e.g. val x: Long = 1 + 1 becomes val x: Long = (1 + 1).toLong() + object IntToLongConversion : KtFakeSourceElementKind() } sealed class AbstractKtSourceElement { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TypeTranslatorImpl.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TypeTranslatorImpl.kt index 427ab3edfd3..4cfd4dd0b42 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TypeTranslatorImpl.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TypeTranslatorImpl.kt @@ -31,7 +31,7 @@ open class TypeTranslatorImpl( object : TypeApproximatorConfiguration.AllFlexibleSameValue() { override val allFlexible: Boolean get() = true override val errorType: Boolean get() = true - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 02e3446b3a7..47f6bb7d0a0 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -306,7 +306,9 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon setOf(byteType, shortType, intType, longType) } - override fun TypeConstructorMarker.isIntegerLiteralTypeConstructor() = false + override fun TypeConstructorMarker.isIntegerLiteralTypeConstructor(): Boolean = false + override fun TypeConstructorMarker.isIntegerLiteralConstantTypeConstructor(): Boolean = false + override fun TypeConstructorMarker.isIntegerConstantOperatorTypeConstructor(): Boolean = false override fun TypeConstructorMarker.isLocalType(): Boolean { if (this !is IrClassSymbol) return false diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt index 68ab9945256..e8268df0dbf 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt @@ -113,4 +113,4 @@ class IrCapturedType( override fun hashCode(): Int { return (captureStatus.hashCode() * 31 + (lowerType?.hashCode() ?: 0)) * 31 + constructor.hashCode() } -} \ No newline at end of file +} diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt index fbd36112098..02df31dafde 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator.commonSuperType import org.jetbrains.kotlin.types.model.* +import org.jetbrains.kotlin.utils.addToStdlib.runIf import java.util.concurrent.ConcurrentHashMap abstract class AbstractTypeApproximator( @@ -340,11 +341,16 @@ abstract class AbstractTypeApproximator( return if (conf.typeVariable(typeConstructor)) null else type.defaultResult(toSuper) } - if (typeConstructor.isIntegerLiteralTypeConstructor()) { - return if (conf.integerLiteralType) + if (typeConstructor.isIntegerLiteralConstantTypeConstructor()) { + return runIf(conf.integerLiteralConstantType) { typeConstructor.getApproximatedIntegerLiteralType().withNullability(type.isMarkedNullable()) - else - null + } + } + + if (typeConstructor.isIntegerConstantOperatorTypeConstructor()) { + return runIf(conf.integerConstantOperatorType) { + typeConstructor.getApproximatedIntegerLiteralType().withNullability(type.isMarkedNullable()) + } } return approximateLocalTypes(type, conf, toSuper) // simple classifier type diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt index c88734dc6f0..57312549eda 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt @@ -19,7 +19,8 @@ open class TypeApproximatorConfiguration { open val dynamic: Boolean get() = false // DynamicType open val rawType: Boolean get() = false // RawTypeImpl open val errorType: Boolean get() = false - open val integerLiteralType: Boolean = false // IntegerLiteralTypeConstructor + open val integerLiteralConstantType: Boolean get() = false // IntegerLiteralTypeConstructor + open val integerConstantOperatorType: Boolean get() = false open val definitelyNotNullType: Boolean get() = true open val intersection: IntersectionStrategy = IntersectionStrategy.TO_COMMON_SUPERTYPE open val intersectionTypesInContravariantPositions = false @@ -47,7 +48,7 @@ open class TypeApproximatorConfiguration { override val allFlexible: Boolean get() = true override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED override val errorType: Boolean get() = true - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } @@ -55,7 +56,7 @@ open class TypeApproximatorConfiguration { override val allFlexible: Boolean get() = true override val errorType: Boolean get() = true override val definitelyNotNullType: Boolean get() = false - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } @@ -75,23 +76,25 @@ open class TypeApproximatorConfiguration { object IncorporationConfiguration : AbstractCapturedTypesApproximation(CaptureStatus.FOR_INCORPORATION) object SubtypeCapturedTypesApproximation : AbstractCapturedTypesApproximation(CaptureStatus.FOR_SUBTYPING) object InternalTypesApproximation : AbstractCapturedTypesApproximation(CaptureStatus.FROM_EXPRESSION) { - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true + override val integerConstantOperatorType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } object FinalApproximationAfterResolutionAndInference : AbstractCapturedTypesApproximation(CaptureStatus.FROM_EXPRESSION) { - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } object TypeArgumentApproximation : AbstractCapturedTypesApproximation(null) { - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true + override val integerConstantOperatorType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } object IntegerLiteralsTypesApproximation : AllFlexibleSameValue() { - override val integerLiteralType: Boolean get() = true + override val integerLiteralConstantType: Boolean get() = true override val allFlexible: Boolean get() = true override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED override val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean get() = { true } diff --git a/compiler/testData/codegen/box/binaryOp/overflowLong.kt b/compiler/testData/codegen/box/binaryOp/overflowLong.kt index dc8dd422a9b..c09a9be37bc 100644 --- a/compiler/testData/codegen/box/binaryOp/overflowLong.kt +++ b/compiler/testData/codegen/box/binaryOp/overflowLong.kt @@ -1,6 +1,4 @@ // LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: don't support legacy feature; for reasons this test is ignored, go to KT-46419 fun box(): String { val a: Long = 2147483647 + 1 diff --git a/compiler/testData/codegen/box/evaluate/intrinsics.kt b/compiler/testData/codegen/box/evaluate/intrinsics.kt index b62836469af..21a740f4b04 100644 --- a/compiler/testData/codegen/box/evaluate/intrinsics.kt +++ b/compiler/testData/codegen/box/evaluate/intrinsics.kt @@ -1,5 +1,6 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR +// FIR status: don't support legacy feature // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/maxValueInt.kt b/compiler/testData/codegen/box/evaluate/maxValueInt.kt index 52315861099..39ba46839ea 100644 --- a/compiler/testData/codegen/box/evaluate/maxValueInt.kt +++ b/compiler/testData/codegen/box/evaluate/maxValueInt.kt @@ -1,5 +1,4 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/minus.kt b/compiler/testData/codegen/box/evaluate/minus.kt index 5c183c1641b..eea652ced37 100644 --- a/compiler/testData/codegen/box/evaluate/minus.kt +++ b/compiler/testData/codegen/box/evaluate/minus.kt @@ -1,5 +1,5 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/multiply.kt b/compiler/testData/codegen/box/evaluate/multiply.kt index d9272e73f4a..43afd2cb7c6 100644 --- a/compiler/testData/codegen/box/evaluate/multiply.kt +++ b/compiler/testData/codegen/box/evaluate/multiply.kt @@ -1,5 +1,5 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/parenthesized.kt b/compiler/testData/codegen/box/evaluate/parenthesized.kt index effee585914..3ed28104757 100644 --- a/compiler/testData/codegen/box/evaluate/parenthesized.kt +++ b/compiler/testData/codegen/box/evaluate/parenthesized.kt @@ -1,5 +1,5 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/plus.kt b/compiler/testData/codegen/box/evaluate/plus.kt index 75bcb69cd21..3aa434b18e1 100644 --- a/compiler/testData/codegen/box/evaluate/plus.kt +++ b/compiler/testData/codegen/box/evaluate/plus.kt @@ -1,5 +1,5 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/codegen/box/evaluate/rem.kt b/compiler/testData/codegen/box/evaluate/rem.kt index 04fa77b2f99..cd8cbd2ec52 100644 --- a/compiler/testData/codegen/box/evaluate/rem.kt +++ b/compiler/testData/codegen/box/evaluate/rem.kt @@ -1,5 +1,5 @@ // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// IGNORE_FIR_DIAGNOSTICS +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_STDLIB diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.fir.kt index 3a1e06b8b5c..50eb8d27a22 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.fir.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass +@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass // EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/long.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/long.fir.kt index c2c992e967c..79d4facad40 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/long.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/long.fir.kt @@ -7,6 +7,6 @@ annotation class Ann( val l3: Long ) -@Ann(1 + 1, java.lang.Long.MAX_VALUE + 1 - 1, java.lang.Long.MAX_VALUE - 1) class MyClass +@Ann(1 + 1, java.lang.Long.MAX_VALUE + 1 - 1, java.lang.Long.MAX_VALUE - 1) class MyClass // EXPECTED: @Ann(l1 = 2.toLong(), l2 = 9223372036854775807.toLong(), l3 = 9223372036854775806.toLong()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.fir.kt index 600553cac3b..b9f9308e6b1 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.fir.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass +@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass // EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.fir.kt index 00f371da955..a04d78ed0c5 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.fir.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass +@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass // EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.fir.kt index 6602b9fab99..e5560ffb577 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.fir.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass +@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass // EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.fir.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.fir.kt index 87bb31f752c..550a3822111 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.fir.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass +@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass // EXPECTED: @Ann(b = 2.toByte(), i = 2, l = 2.toLong(), s = 2.toShort()) diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt index b6fda821e1a..e6545c73e44 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt @@ -17,7 +17,7 @@ fun test() { fooByte(1 - 1.toLong()) fooByte(1 - 1.toShort()) - fooLong(1 - 1) + fooLong(1 - 1) fooLong(1 - 1.toInt()) fooLong(1 - 1.toByte()) fooLong(1 - 1.toLong()) diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt index 69a770e7cc5..c2f373c4320 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt @@ -1,5 +1,5 @@ val p1: Int = 1 - 1 -val p2: Long = 1 - 1 +val p2: Long = 1 - 1 val p3: Byte = 1 - 1 val p4: Short = 1 - 1 diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt index be88afc1c70..b9505ce3840 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt @@ -7,21 +7,21 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 + 1) fooByte(1 + 1) - fooLong(1 + 1) + fooLong(1 + 1) fooShort(1 + 1) fooInt(1 * 1) fooByte(1 * 1) - fooLong(1 * 1) + fooLong(1 * 1) fooShort(1 * 1) fooInt(1 / 1) fooByte(1 / 1) - fooLong(1 / 1) + fooLong(1 / 1) fooShort(1 / 1) fooInt(1 % 1) fooByte(1 % 1) - fooLong(1 % 1) + fooLong(1 % 1) fooShort(1 % 1) } diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt index 5aa415298da..cd9c1813f3d 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt @@ -7,21 +7,21 @@ fun fooShort(p: Short) = p fun test() { fooInt(1.plus(1)) fooByte(1.plus(1)) - fooLong(1.plus(1)) + fooLong(1.plus(1)) fooShort(1.plus(1)) fooInt(1.times(1)) fooByte(1.times(1)) - fooLong(1.times(1)) + fooLong(1.times(1)) fooShort(1.times(1)) fooInt(1.div(1)) fooByte(1.div(1)) - fooLong(1.div(1)) + fooLong(1.div(1)) fooShort(1.div(1)) fooInt(1.rem(1)) fooByte(1.rem(1)) - fooLong(1.rem(1)) + fooLong(1.rem(1)) fooShort(1.rem(1)) } diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt index fc5fa96c3a3..a8d60b15873 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt @@ -7,21 +7,21 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 plus 1) fooByte(1 plus 1) - fooLong(1 plus 1) + fooLong(1 plus 1) fooShort(1 plus 1) fooInt(1 times 1) fooByte(1 times 1) - fooLong(1 times 1) + fooLong(1 times 1) fooShort(1 times 1) fooInt(1 div 1) fooByte(1 div 1) - fooLong(1 div 1) + fooLong(1 div 1) fooShort(1 div 1) fooInt(1 rem 1) fooByte(1 rem 1) - fooLong(1 rem 1) + fooLong(1 rem 1) fooShort(1 rem 1) } diff --git a/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt b/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt new file mode 100644 index 00000000000..9229e78f278 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt @@ -0,0 +1,13 @@ +// LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition +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 4ff230d0a85..f533ba18019 100644 --- a/compiler/testData/diagnostics/tests/evaluate/parentesized.kt +++ b/compiler/testData/diagnostics/tests/evaluate/parentesized.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition val p1: Byte = (1 + 2) * 2 val p2: Short = (1 + 2) * 2 diff --git a/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.kt b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.kt new file mode 100644 index 00000000000..c3184aa0c8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.kt @@ -0,0 +1,65 @@ +// SKIP_TXT +// FIR_DUMP +// ISSUE: KT-38895, KT-50996, KT-51000 + +interface A +interface B + +fun takeByte(x: Byte) {} + +fun takeInt(x: Int) {} +fun takeNullableInt(x: Int) {} + +fun takeLong(x: Long) {} +fun takeNullableLong(x: Long) {} + +fun takeOverloaded(x: Int): A = null!! // (1) +fun takeOverloaded(x: Long): B = null!! // (2) + +fun takeA(a: A) {} +fun takeB(b: B) {} + +fun test_constants() { + takeByte(1 + 1) // error + takeInt(1 + 1 + 1) // OK + takeNullableInt(1 + 1 + 1) // OK + takeLong(1 + 1 + 1) // will be OK with implicit widening conversion + takeNullableLong(1 + 1 + 1) // will be OK with implicit widening conversion + val x = takeOverloaded(2147483648 - 1 + 1) // now resolved to (1), will be resolved to (2) + takeA(x) + takeB(x) +} + +val topLevelIntProperty: Int = 1 + 1 + 1 +val topLevelLongProperty: Long = 1 + 1 + 1 +val topLevelImplicitIntProperty = 1 + 1 + 1 +val topLevelImplicitLongProperty = 3000000000 * 2 + 1 + +fun testTopLevelProperties() { + // OK + takeInt(topLevelIntProperty) + takeLong(topLevelLongProperty) + takeInt(topLevelImplicitIntProperty) + takeLong(topLevelImplicitLongProperty) + + // no conversion for properties + takeLong(topLevelIntProperty) + takeLong(topLevelImplicitIntProperty) +} + +fun testLocalProperties() { + val localIntProperty: Int = 1 + 1 + val localLongProperty: Long = 1 + 1 + val localImplicitIntProperty = 1 + 1 + val localImplicitLongProperty = 3000000000 * 2 + + // OK + takeInt(localIntProperty) + takeLong(localLongProperty) + takeInt(localImplicitIntProperty) + takeLong(localImplicitLongProperty) + + // no conversion for properties + takeLong(localIntProperty) + takeLong(localImplicitIntProperty) +} diff --git a/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.txt b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.txt new file mode 100644 index 00000000000..d860e6c5045 --- /dev/null +++ b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.fir.txt @@ -0,0 +1,63 @@ +FILE: intToLongConversion.fir.kt + public abstract interface A : R|kotlin/Any| { + } + public abstract interface B : R|kotlin/Any| { + } + public final fun takeByte(x: R|kotlin/Byte|): R|kotlin/Unit| { + } + public final fun takeInt(x: R|kotlin/Int|): R|kotlin/Unit| { + } + public final fun takeNullableInt(x: R|kotlin/Int|): R|kotlin/Unit| { + } + public final fun takeLong(x: R|kotlin/Long|): R|kotlin/Unit| { + } + public final fun takeNullableLong(x: R|kotlin/Long|): R|kotlin/Unit| { + } + public final fun takeOverloaded(x: R|kotlin/Int|): R|A| { + ^takeOverloaded Null(null)!! + } + public final fun takeOverloaded(x: R|kotlin/Long|): R|B| { + ^takeOverloaded Null(null)!! + } + public final fun takeA(a: R|A|): R|kotlin/Unit| { + } + public final fun takeB(b: R|B|): R|kotlin/Unit| { + } + public final fun test_constants(): R|kotlin/Unit| { + #(Int(1).R|kotlin/Int.plus|(Int(1))) + R|/takeInt|(Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1))) + R|/takeNullableInt|(Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1))) + R|/takeLong|(Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.toLong|()) + R|/takeNullableLong|(Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.toLong|()) + lval x: R|B| = R|/takeOverloaded|(Long(2147483648).R|kotlin/Long.minus|(Int(1)).R|kotlin/Long.plus|(Int(1))) + #(R|/x|) + R|/takeB|(R|/x|) + } + public final val topLevelIntProperty: R|kotlin/Int| = Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1)) + public get(): R|kotlin/Int| + public final val topLevelLongProperty: R|kotlin/Long| = Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.toLong|() + public get(): R|kotlin/Long| + public final val topLevelImplicitIntProperty: R|kotlin/Int| = Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.plus|(Int(1)) + public get(): R|kotlin/Int| + public final val topLevelImplicitLongProperty: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)) + public get(): R|kotlin/Long| + public final fun testTopLevelProperties(): R|kotlin/Unit| { + R|/takeInt|(R|/topLevelIntProperty|) + R|/takeLong|(R|/topLevelLongProperty|) + R|/takeInt|(R|/topLevelImplicitIntProperty|) + R|/takeLong|(R|/topLevelImplicitLongProperty|) + #(R|/topLevelIntProperty|) + #(R|/topLevelImplicitIntProperty|) + } + public final fun testLocalProperties(): R|kotlin/Unit| { + lval localIntProperty: R|kotlin/Int| = Int(1).R|kotlin/Int.plus|(Int(1)) + lval localLongProperty: R|kotlin/Long| = Int(1).R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.toLong|() + lval localImplicitIntProperty: R|kotlin/Int| = Int(1).R|kotlin/Int.plus|(Int(1)) + lval localImplicitLongProperty: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)) + R|/takeInt|(R|/localIntProperty|) + R|/takeLong|(R|/localLongProperty|) + R|/takeInt|(R|/localImplicitIntProperty|) + R|/takeLong|(R|/localImplicitLongProperty|) + #(R|/localIntProperty|) + #(R|/localImplicitIntProperty|) + } diff --git a/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt new file mode 100644 index 00000000000..97ae82e84b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt @@ -0,0 +1,65 @@ +// SKIP_TXT +// FIR_DUMP +// ISSUE: KT-38895, KT-50996, KT-51000 + +interface A +interface B + +fun takeByte(x: Byte) {} + +fun takeInt(x: Int) {} +fun takeNullableInt(x: Int) {} + +fun takeLong(x: Long) {} +fun takeNullableLong(x: Long) {} + +fun takeOverloaded(x: Int): A = null!! // (1) +fun takeOverloaded(x: Long): B = null!! // (2) + +fun takeA(a: A) {} +fun takeB(b: B) {} + +fun test_constants() { + takeByte(1 + 1) // error + takeInt(1 + 1 + 1) // OK + takeNullableInt(1 + 1 + 1) // OK + takeLong(1 + 1 + 1) // will be OK with implicit widening conversion + takeNullableLong(1 + 1 + 1) // will be OK with implicit widening conversion + val x = takeOverloaded(2147483648 - 1 + 1) // now resolved to (1), will be resolved to (2) + takeA(x) + takeB(x) +} + +val topLevelIntProperty: Int = 1 + 1 + 1 +val topLevelLongProperty: Long = 1 + 1 + 1 +val topLevelImplicitIntProperty = 1 + 1 + 1 +val topLevelImplicitLongProperty = 3000000000 * 2 + 1 + +fun testTopLevelProperties() { + // OK + takeInt(topLevelIntProperty) + takeLong(topLevelLongProperty) + takeInt(topLevelImplicitIntProperty) + takeLong(topLevelImplicitLongProperty) + + // no conversion for properties + takeLong(topLevelIntProperty) + takeLong(topLevelImplicitIntProperty) +} + +fun testLocalProperties() { + val localIntProperty: Int = 1 + 1 + val localLongProperty: Long = 1 + 1 + val localImplicitIntProperty = 1 + 1 + val localImplicitLongProperty = 3000000000 * 2 + + // OK + takeInt(localIntProperty) + takeLong(localLongProperty) + takeInt(localImplicitIntProperty) + takeLong(localImplicitLongProperty) + + // no conversion for properties + takeLong(localIntProperty) + takeLong(localImplicitIntProperty) +} diff --git a/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt b/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt new file mode 100644 index 00000000000..4a63ebef2c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt @@ -0,0 +1,24 @@ +// FIR_IDENTICAL +// ISSUE: KT-51003 + +interface Assert + +fun createAssert(value: T): Assert = null!! + +fun > Assert.isGreaterThanOrEqualTo(other: A) {} + +fun test_1(long: Long) { + // FE 1.0: OK + // FIR: ARGUMENT_TYPE_MISMATCH + createAssert(long).isGreaterThanOrEqualTo(10 * 10) +} + +fun getNullableLong(): Long? = null +fun takeLong(x: Long) {} + +fun test_2() { + val x = getNullableLong() ?: 10 * 60 + takeLong(x) + // FE 1.0 infers type of `x` to `Long` + // FIR infers it to `Number` as `CST(Long, Int)` +} diff --git a/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.txt b/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.txt new file mode 100644 index 00000000000..7a8e1c33922 --- /dev/null +++ b/compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.txt @@ -0,0 +1,14 @@ +package + +public fun createAssert(/*0*/ value: T): Assert +public fun getNullableLong(): kotlin.Long? +public fun takeLong(/*0*/ x: kotlin.Long): kotlin.Unit +public fun test_1(/*0*/ long: kotlin.Long): kotlin.Unit +public fun test_2(): kotlin.Unit +public fun > Assert.isGreaterThanOrEqualTo(/*0*/ other: A): kotlin.Unit + +public interface Assert { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt deleted file mode 100644 index a4badca8dae..00000000000 --- a/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// ISSUE: Kt-47447, KT-47729 - -fun takeLong(value : Long) {} -fun takeInt(value : Int) {} -fun takeAny(value : Any) {} -fun takeLongX(value : Long?) {} -fun takeIntX(value : Int?) {} -fun takeAnyX(value : Any?) {} -fun takeGeneric(value : A) {} -fun takeGenericX(value : A?) {} - -fun test_1() { - takeLong(1 + 1) // ok - takeInt(1 + 1) // ok - takeAny(1 + 1) // ok - takeLongX(1 + 1) // ok - takeIntX(1 + 1) // ok - takeAnyX(1 + 1) // ok - takeGeneric(1 + 1) // ok - takeGenericX(1 + 1) // ok -} diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729.kt b/compiler/testData/diagnostics/tests/numbers/kt47729.kt index f7ff85b005d..2ec025df9e6 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt deleted file mode 100644 index 8b2f1d2fd79..00000000000 --- a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -// ISSUE: Kt-47447, KT-47729 - -fun takeLong(x: Long) {} - -object Foo { - var longProperty: Long = 0 - - infix fun infixOperator(x: Long) {} -} - -// Should be ok in all places -fun test() { - takeLong(1 + 1) - takeLong((1 + 1)) - Foo.longProperty = 1 + 1 - Foo.longProperty = (1 + 1) - Foo infixOperator 1 + 1 - Foo infixOperator (1 + 1) -} diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt index df992e251ce..0ee887ff059 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt deleted file mode 100644 index cd4a8c44a46..00000000000 --- a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -// !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 index 7406c755b3b..f335d3e2790 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition fun foo(ttlMillis: Long = 5 * 60 * 1000) {} diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.fir.kt new file mode 100644 index 00000000000..af14b49ce39 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.fir.kt @@ -0,0 +1,6 @@ +// 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.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt index f2dffd6c754..a29cd7d8e1c 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_enabled.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // LANGUAGE: +ApproximateIntegerLiteralTypesInReceiverPosition fun foo(ttlMillis: Long = 5 * 60 * 1000) {} diff --git a/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.fir.kt b/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.fir.kt index b205d8a2086..cde436975cb 100644 --- a/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.fir.kt @@ -7,21 +7,21 @@ abstract class C { } fun testLongDotCall(c1: C) { - c1.takeT(1.plus(2)) - c1.takeT(1.minus(2)) - c1.takeT(1.times(2)) - c1.takeT(1.div(2)) - c1.takeT(1.rem(2)) + c1.takeT(1.plus(2)) + c1.takeT(1.minus(2)) + c1.takeT(1.times(2)) + c1.takeT(1.div(2)) + c1.takeT(1.rem(2)) c1.takeT(1.inc()) c1.takeT(1.dec()) c1.takeT(1.unaryPlus()) c1.takeT(1.unaryMinus()) - c1.takeT(1.shl(2)) - c1.takeT(1.shr(2)) - c1.takeT(1.ushr(2)) - c1.takeT(1.and(2)) - c1.takeT(1.or(2)) - c1.takeT(1.xor(2)) + c1.takeT(1.shl(2)) + c1.takeT(1.shr(2)) + c1.takeT(1.ushr(2)) + c1.takeT(1.and(2)) + c1.takeT(1.or(2)) + c1.takeT(1.xor(2)) c1.takeT(1.inv()) } @@ -42,19 +42,19 @@ fun testByteDotCall(c3: C) { } fun testLongOperatorInfixCall(c4: C) { - c4.takeT(1 + 2) - c4.takeT(1 - 2) - c4.takeT(1 * 2) - c4.takeT(1 / 2) - c4.takeT(1 % 2) + c4.takeT(1 + 2) + c4.takeT(1 - 2) + c4.takeT(1 * 2) + c4.takeT(1 / 2) + c4.takeT(1 % 2) c4.takeT(+1) c4.takeT(-1) - c4.takeT(1 shl 2) - c4.takeT(1 shr 2) - c4.takeT(1 ushr 2) - c4.takeT(1 and 2) - c4.takeT(1 or 2) - c4.takeT(1 xor 2) + c4.takeT(1 shl 2) + c4.takeT(1 shr 2) + c4.takeT(1 ushr 2) + c4.takeT(1 and 2) + c4.takeT(1 or 2) + c4.takeT(1 xor 2) } fun testShortOperatorInfixCall(c5: C) { diff --git a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.fir.kt b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.fir.kt index 554cbb4ca2c..9e1a41212ec 100644 --- a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.fir.kt @@ -41,24 +41,24 @@ fun testByteUnaryOperators() { } fun testLongBinaryOperators() { - takeLong(2 + 1) - takeLong(2 - 1) - takeLong(2 * 1) - takeLong(2 / 1) - takeLong(2 % 1) + 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.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) + takeLong(2 and 1) + takeLong(2 or 1) + takeLong(2 xor 1) // positive takeLong(2 * 100000000000) diff --git a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt index 7285b3c873c..44a34269510 100644 --- a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt @@ -42,24 +42,24 @@ fun testByteUnaryOperators() { // all positive fun testLongBinaryOperators() { - takeLong(2 + 1) - takeLong(2 - 1) - takeLong(2 * 1) - takeLong(2 / 1) - takeLong(2 % 1) + 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.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) + takeLong(2 and 1) + takeLong(2 or 1) + takeLong(2 xor 1) takeLong(2 * 100000000000) } diff --git a/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt index 60f181adef4..e79119aa4d9 100644 --- a/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt @@ -8,7 +8,7 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 % 1) fooByte(1 % 1) - fooLong(1 % 1) + fooLong(1 % 1) fooShort(1 % 1) } diff --git a/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsTypeCheck.fir.kt b/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsTypeCheck.fir.kt index f35926bf4f7..8c858e8c5ff 100644 --- a/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsTypeCheck.fir.kt +++ b/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsTypeCheck.fir.kt @@ -13,8 +13,8 @@ val u3: UInt? = u1 val i0: Int = 1u -val m0 = -1u -val m1: UInt = -1u +val m0 = -1u +val m1: UInt = -1u val h1 = 0xFFu val h2: UShort = 0xFFu 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 fe72feb4f56..e23b7fc69ab 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 @@ -17483,6 +17483,28 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/integerLiterals") + @TestDataPath("$PROJECT_ROOT") + public class IntegerLiterals { + @Test + public void testAllFilesPresentInIntegerLiterals() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/integerLiterals"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("intToLongConversion.kt") + public void testIntToLongConversion() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/intToLongConversion.kt"); + } + + @Test + @TestMetadata("literalsInInference.kt") + public void testLiteralsInInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/integerLiterals/literalsInInference.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/j+k") @TestDataPath("$PROJECT_ROOT") diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index 9a42a4b2199..89e24ecb422 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -381,6 +381,8 @@ interface TypeSystemContext : TypeSystemOptimizationContext { fun TypeConstructorMarker.isClassTypeConstructor(): Boolean fun TypeConstructorMarker.isInterface(): Boolean fun TypeConstructorMarker.isIntegerLiteralTypeConstructor(): Boolean + fun TypeConstructorMarker.isIntegerLiteralConstantTypeConstructor(): Boolean + fun TypeConstructorMarker.isIntegerConstantOperatorTypeConstructor(): Boolean fun TypeConstructorMarker.isLocalType(): Boolean fun TypeConstructorMarker.isAnonymous(): Boolean fun TypeConstructorMarker.getTypeParameterClassifier(): TypeParameterMarker? diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 171deec1e85..9acb709f073 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -45,6 +45,14 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return this is IntegerLiteralTypeConstructor } + override fun TypeConstructorMarker.isIntegerLiteralConstantTypeConstructor(): Boolean { + return isIntegerLiteralTypeConstructor() + } + + override fun TypeConstructorMarker.isIntegerConstantOperatorTypeConstructor(): Boolean { + return false + } + override fun TypeConstructorMarker.isLocalType(): Boolean { require(this is TypeConstructor, this::errorMessage) return declarationDescriptor?.classId?.isLocal == true