diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/DiagnosticData.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/DiagnosticData.kt index d2073d03f10..fec2b62c615 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/DiagnosticData.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/DiagnosticData.kt @@ -56,6 +56,7 @@ enum class PositioningStrategy(private val strategy: String? = null) { VALUE_ARGUMENTS, SUPERTYPES_LIST, RETURN_WITH_LABEL, + INT_LITERAL_OUT_OF_RANGE, LONG_LITERAL_SUFFIX, ; diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 28c587e4ffa..501d3ca3c15 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -61,6 +61,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() { val EMPTY_CHARACTER_LITERAL by error() val TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL by error() val ILLEGAL_ESCAPE by error() + val INT_LITERAL_OUT_OF_RANGE by error() val WRONG_LONG_SUFFIX by error(PositioningStrategy.LONG_LITERAL_SUFFIX) } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index e42adaebd23..93a9d642e31 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -86,6 +86,7 @@ object FirErrors { val EMPTY_CHARACTER_LITERAL by error0() val TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL by error0() val ILLEGAL_ESCAPE by error0() + val INT_LITERAL_OUT_OF_RANGE by error0() val WRONG_LONG_SUFFIX by error0(SourceElementPositioningStrategies.LONG_LITERAL_SUFFIX) // Unresolved diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 3634addb3a2..fab5cabf9b8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -179,6 +179,7 @@ private fun ConeSimpleDiagnostic.getFactory(): FirDiagnosticFactory0 FirErrors.UNKNOWN_CALLABLE_KIND DiagnosticKind.IllegalProjectionUsage -> FirErrors.ILLEGAL_PROJECTION_USAGE DiagnosticKind.MissingStdlibClass -> FirErrors.MISSING_STDLIB_CLASS + DiagnosticKind.IntLiteralOutOfRange -> FirErrors.INT_LITERAL_OUT_OF_RANGE DiagnosticKind.WrongLongSuffix -> FirErrors.WRONG_LONG_SUFFIX DiagnosticKind.Other -> FirErrors.OTHER_ERROR DiagnosticKind.IncorrectCharacterLiteral -> FirErrors.INCORRECT_CHARACTER_LITERAL diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index fb2a0419e4a..c171e3ad087 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -295,6 +295,12 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte val number: Long? val kind = when { + convertedText == null -> { + number = null + diagnostic = DiagnosticKind.IntLiteralOutOfRange + ConstantValueKind.IntegerLiteral + } + convertedText !is Long -> return reportIncorrectConstant(DiagnosticKind.IllegalConstExpression) hasUnsignedLongSuffix(text) -> { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index 20d9583d606..f680c1379cf 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -36,6 +36,7 @@ enum class DiagnosticKind { TooManyCharactersInCharacterLiteral, IllegalEscape, + IntLiteralOutOfRange, WrongLongSuffix, Other diff --git a/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt index 4c4c44c2141..ace8eca8e5a 100644 --- a/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt @@ -6,12 +6,12 @@ fun foo(i: Int) = i fun bar(l: Long) = l fun main() { - val i = 111111111111111777777777777777 + val i = 111111111111111777777777777777 //todo add diagnostic text messages //report only 'The value is out of range' //not 'An integer literal does not conform to the expected type Int/Long' - val l: Long = 1111111111111117777777777777777 - foo(11111111111111177777777777777) - bar(11111111111111177777777777777) + val l: Long = 1111111111111117777777777777777 + foo(11111111111111177777777777777) + bar(11111111111111177777777777777) } diff --git a/compiler/testData/diagnostics/tests/unsignedTypes/conversions/signedToUnsignedConversionWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/signedToUnsignedConversionWithExpectedType.fir.kt index 8569081069a..6be76f49a5b 100644 --- a/compiler/testData/diagnostics/tests/unsignedTypes/conversions/signedToUnsignedConversionWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/signedToUnsignedConversionWithExpectedType.fir.kt @@ -27,7 +27,7 @@ fun test() { takeUInt(1) takeULong(1) - takeULong(18446744073709551615) + takeULong(18446744073709551615) takeULong(1844674407370955161) takeULong(18446744073709551615u) diff --git a/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsOverflowSignedBorder.fir.kt b/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsOverflowSignedBorder.fir.kt index e415c35032d..42681aac5b8 100644 --- a/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsOverflowSignedBorder.fir.kt +++ b/compiler/testData/diagnostics/tests/unsignedTypes/unsignedLiteralsOverflowSignedBorder.fir.kt @@ -22,4 +22,4 @@ fun test() { } val s1: UByte = 256u -val s2 = 18446744073709551616u +val s2 = 18446744073709551616u diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.fir.kt deleted file mode 100644 index 7538b2df1f8..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -// TESTCASE NUMBER: 1 -val value_1 = 0b - -// TESTCASE NUMBER: 2 -val value_2 = 0B diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.kt index 599c67da8ec..76b0ab70f8e 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/binary-integer-literals/p-1/neg/1.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL /* * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) * diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.fir.kt deleted file mode 100644 index 84b2bd03206..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -// TESTCASE NUMBER: 1 -val value_1 = 0x - -// TESTCASE NUMBER: 2 -val value_2 = 0X diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.kt index 107e386b047..6d639974378 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/integer-literals/hexadecimal-integer-literals/p-1/neg/1.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL /* * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) * diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/1.1.fir.kt index 08221a9fcb5..a88253e6d32 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/1.1.fir.kt @@ -1,14 +1,14 @@ // TESTCASE NUMBER: 1 -val value_1 = 0bl +val value_1 = 0bl // TESTCASE NUMBER: 2 -val value_2 = 0BL +val value_2 = 0BL // TESTCASE NUMBER: 3 -val value_3 = 0Xl +val value_3 = 0Xl // TESTCASE NUMBER: 4 -val value_4 = 0xL +val value_4 = 0xL // TESTCASE NUMBER: 5 val value_5 = 0b_l diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.3.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.3.fir.kt index 3a32e14e067..5a920ee4ba6 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.3.fir.kt @@ -101,12 +101,12 @@ fun case_5() { // TESTCASE NUMBER: 6 fun case_6() { - checkSubtype(-100000000000000000000000000000000) - checkSubtype(-100000000000000000000000000000000) - checkSubtype(-100000000000000000000000000000000) - checkSubtype(-100000000000000000000000000000000) - -100000000000000000000000000000000 checkType { check() } - -100000000000000000000000000000000 checkType { check() } - -100000000000000000000000000000000 checkType { check() } - -100000000000000000000000000000000 checkType { check() } + checkSubtype(-100000000000000000000000000000000) + checkSubtype(-100000000000000000000000000000000) + checkSubtype(-100000000000000000000000000000000) + checkSubtype(-100000000000000000000000000000000) + -100000000000000000000000000000000 checkType { check() } + -100000000000000000000000000000000 checkType { check() } + -100000000000000000000000000000000 checkType { check() } + -100000000000000000000000000000000 checkType { check() } } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.4.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.4.fir.kt index 800df3eba7c..91a3feda298 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.4.fir.kt @@ -2,24 +2,24 @@ // TESTCASE NUMBER: 1 fun case_1() { - checkSubtype(-9223372036854775808L) - -9223372036854775808L checkType { check() } + checkSubtype(-9223372036854775808L) + -9223372036854775808L checkType { check() } - checkSubtype(9223372036854775808L) - 9223372036854775808L checkType { check() } + checkSubtype(9223372036854775808L) + 9223372036854775808L checkType { check() } } // TESTCASE NUMBER: 2 fun case_2() { - checkSubtype(100000000000000000000000000000000L) - 100000000000000000000000000000000L checkType { check() } + checkSubtype(100000000000000000000000000000000L) + 100000000000000000000000000000000L checkType { check() } - checkSubtype(100000000000000000000000000000000l) - 100000000000000000000000000000000l checkType { check() } + checkSubtype(100000000000000000000000000000000l) + 100000000000000000000000000000000l checkType { check() } - checkSubtype(-100000000000000000000000000000000L) - -100000000000000000000000000000000L checkType { check() } + checkSubtype(-100000000000000000000000000000000L) + -100000000000000000000000000000000L checkType { check() } - checkSubtype(-100000000000000000000000000000000l) - -100000000000000000000000000000000l checkType { check() } + checkSubtype(-100000000000000000000000000000000l) + -100000000000000000000000000000000l checkType { check() } } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.5.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.5.fir.kt index acc3c5b77fe..09ee3bbf06c 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.5.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/constant-literals/the-types-for-integer-literals/p-1/neg/2.5.fir.kt @@ -27,8 +27,8 @@ fun case_1() { f1(-2147483648) f1(9223372036854775807) f1(-9223372036854775807) - f1(1000000000000000000000000000000000000000000000000) - f1(-1000000000000000000000000000000000000000000000000) + f1(1000000000000000000000000000000000000000000000000) + f1(-1000000000000000000000000000000000000000000000000) } // TESTCASE NUMBER: 2 @@ -39,20 +39,20 @@ fun case_2() { f2(-2147483648) f2(9223372036854775807) f2(-9223372036854775807) - f2(1000000000000000000000000000000000000000000000000) - f2(-1000000000000000000000000000000000000000000000000) + f2(1000000000000000000000000000000000000000000000000) + f2(-1000000000000000000000000000000000000000000000000) } // TESTCASE NUMBER: 3 fun case_3() { f3(9223372036854775807) f3(-9223372036854775807) - f3(1000000000000000000000000000000000000000000000000) - f3(-1000000000000000000000000000000000000000000000000) + f3(1000000000000000000000000000000000000000000000000) + f3(-1000000000000000000000000000000000000000000000000) } // TESTCASE NUMBER: 4 fun case_4() { - f3(1000000000000000000000000000000000000000000000000) - f3(-1000000000000000000000000000000000000000000000000) + f3(1000000000000000000000000000000000000000000000000) + f3(-1000000000000000000000000000000000000000000000000) } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index edd743d0e58..efdc638e5ca 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -149,6 +149,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.INT_LITERAL_OUT_OF_RANGE) { firDiagnostic -> + IntLiteralOutOfRangeImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.WRONG_LONG_SUFFIX) { firDiagnostic -> WrongLongSuffixImpl( firDiagnostic as FirPsiDiagnostic<*>, diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 4d7b93124cf..37a40e7c188 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -124,6 +124,10 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = IllegalEscape::class } + abstract class IntLiteralOutOfRange : KtFirDiagnostic() { + override val diagnosticClass get() = IntLiteralOutOfRange::class + } + abstract class WrongLongSuffix : KtFirDiagnostic() { override val diagnosticClass get() = WrongLongSuffix::class } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index f7723ff44ca..170790c1bf6 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -173,6 +173,13 @@ internal class IllegalEscapeImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class IntLiteralOutOfRangeImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.IntLiteralOutOfRange(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class WrongLongSuffixImpl( firDiagnostic: FirPsiDiagnostic<*>, override val token: ValidityToken,