From 3c4898b642dcc14c10be0e640623abf6a180cf89 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 2 Sep 2019 23:10:23 -0400 Subject: [PATCH 1/4] Added error for numeric literals larger than 2^53 - 1 --- src/compiler/checker.ts | 31 +++- src/compiler/diagnosticMessages.json | 4 + .../impreciseNumericLiterals.errors.txt | 103 +++++++++++ .../reference/impreciseNumericLiterals.js | 116 ++++++++++++ .../impreciseNumericLiterals.symbols | 60 +++++++ .../reference/impreciseNumericLiterals.types | 166 ++++++++++++++++++ .../compiler/impreciseNumericLiterals.ts | 58 ++++++ 7 files changed, 531 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/impreciseNumericLiterals.errors.txt create mode 100644 tests/baselines/reference/impreciseNumericLiterals.js create mode 100644 tests/baselines/reference/impreciseNumericLiterals.symbols create mode 100644 tests/baselines/reference/impreciseNumericLiterals.types create mode 100644 tests/cases/compiler/impreciseNumericLiterals.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfad47b65336f..fbc5fff7fef86 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33663,9 +33663,9 @@ namespace ts { } function checkGrammarNumericLiteral(node: NumericLiteral): boolean { - // Grammar checking + let diagnosticMessage: DiagnosticMessage | undefined; + if (node.numericLiteralFlags & TokenFlags.Octal) { - let diagnosticMessage: DiagnosticMessage | undefined; if (languageVersion >= ScriptTarget.ES5) { diagnosticMessage = Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0; } @@ -33675,14 +33675,31 @@ namespace ts { else if (isChildOfNodeWithKind(node, SyntaxKind.EnumMember)) { diagnosticMessage = Diagnostics.Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0; } - if (diagnosticMessage) { - const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken; - const literal = (withMinus ? "-" : "") + "0o" + node.text; - return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal); - } } + + if (!diagnosticMessage && numericLiteralValueImpreciselyLarge(node.text)) { + diagnosticMessage = Diagnostics.Numeric_literal_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_an_integer; + } + + if (diagnosticMessage) { + const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken; + const literal = (withMinus ? "-" : "") + "0o" + node.text; + return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal); + } + return false; } + + function numericLiteralValueImpreciselyLarge(text: string) { + // We can quickly bail out in two common cases: + // * Literals with 15 or fewer characters, as they aren't long enough to reach 2^53 - 1 + // * Fractional numbers (e.g. 9000000000000000000000000000.000000001) are inherently imprecise anyway + if (text.length <= 15 || text.indexOf(".") !== -1) { + return false; + } + + return Number(text) >= Math.pow(2, 53) - 1; + } function checkGrammarBigIntLiteral(node: BigIntLiteral): boolean { const literalType = isLiteralTypeNode(node.parent) || diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b296c224d089d..bcda838a32cc2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1035,6 +1035,10 @@ "category": "Error", "code": 1356 }, + "Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer.": { + "category": "Error", + "code": 1357 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/impreciseNumericLiterals.errors.txt b/tests/baselines/reference/impreciseNumericLiterals.errors.txt new file mode 100644 index 0000000000000..88e39a7b0ed52 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.errors.txt @@ -0,0 +1,103 @@ +tests/cases/compiler/impreciseNumericLiterals.ts(17,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(18,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(19,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(20,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(24,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(25,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(26,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(42,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(43,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(44,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(45,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(56,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(57,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(58,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + + +==== tests/cases/compiler/impreciseNumericLiterals.ts (14 errors) ==== + 1; + 12; + 123; + 1234; + 12345; + 123456; + 1234567; + 12345678; + 123456789; + 1234567890; + 12345678901; + 123456789012; + 1234567890123; + 12345678901234; + 123456789012345; + 1234567890123456; + 12345678901234567; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 123456789012345678; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 1234567890123456789; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 12345678901234567890; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + + 9007199254740989; + 9007199254740990; + 9007199254740991; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 9007199254740992; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 9007199254740993; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + + 0x1; + 0x12; + 0x123; + 0x1234; + 0x12345; + 0x123456; + 0x1234567; + 0x12345678; + 0x123456789; + 0x1234567890; + 0x12345678901; + 0x123456789012; + 0x1234567890123; + 0x12345678901234; + 0x123456789012345; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x1234567890123456; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x12345678901234567; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x123456789012345678; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x1234567890123456789; + 0x12345678901234567890; + 0x123456789012345678901; + 0x1234567890123456789012; + 0x12345678901234567890123; + 0x123456789012345678901234; + 0x1234567890123456789012345; + + 0x19999999999998; + 0x19999999999999; + 0x20000000000000; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x20000000000001; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. + 0x20000000000002; + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. \ No newline at end of file diff --git a/tests/baselines/reference/impreciseNumericLiterals.js b/tests/baselines/reference/impreciseNumericLiterals.js new file mode 100644 index 0000000000000..b7227218108be --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.js @@ -0,0 +1,116 @@ +//// [impreciseNumericLiterals.ts] +1; +12; +123; +1234; +12345; +123456; +1234567; +12345678; +123456789; +1234567890; +12345678901; +123456789012; +1234567890123; +12345678901234; +123456789012345; +1234567890123456; +12345678901234567; +123456789012345678; +1234567890123456789; +12345678901234567890; + +9007199254740989; +9007199254740990; +9007199254740991; +9007199254740992; +9007199254740993; + +0x1; +0x12; +0x123; +0x1234; +0x12345; +0x123456; +0x1234567; +0x12345678; +0x123456789; +0x1234567890; +0x12345678901; +0x123456789012; +0x1234567890123; +0x12345678901234; +0x123456789012345; +0x1234567890123456; +0x12345678901234567; +0x123456789012345678; +0x1234567890123456789; +0x12345678901234567890; +0x123456789012345678901; +0x1234567890123456789012; +0x12345678901234567890123; +0x123456789012345678901234; +0x1234567890123456789012345; + +0x19999999999998; +0x19999999999999; +0x20000000000000; +0x20000000000001; +0x20000000000002; + +//// [impreciseNumericLiterals.js] +1; +12; +123; +1234; +12345; +123456; +1234567; +12345678; +123456789; +1234567890; +12345678901; +123456789012; +1234567890123; +12345678901234; +123456789012345; +1234567890123456; +12345678901234567; +123456789012345678; +1234567890123456789; +12345678901234567890; +9007199254740989; +9007199254740990; +9007199254740991; +9007199254740992; +9007199254740993; +0x1; +0x12; +0x123; +0x1234; +0x12345; +0x123456; +0x1234567; +0x12345678; +0x123456789; +0x1234567890; +0x12345678901; +0x123456789012; +0x1234567890123; +0x12345678901234; +0x123456789012345; +0x1234567890123456; +0x12345678901234567; +0x123456789012345678; +0x1234567890123456789; +0x12345678901234567890; +0x123456789012345678901; +0x1234567890123456789012; +0x12345678901234567890123; +0x123456789012345678901234; +0x1234567890123456789012345; +0x19999999999998; +0x19999999999999; +0x20000000000000; +0x20000000000001; +0x20000000000002; diff --git a/tests/baselines/reference/impreciseNumericLiterals.symbols b/tests/baselines/reference/impreciseNumericLiterals.symbols new file mode 100644 index 0000000000000..2b3d0c27b5ced --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.symbols @@ -0,0 +1,60 @@ +=== tests/cases/compiler/impreciseNumericLiterals.ts === +1; +No type information for this code.12; +No type information for this code.123; +No type information for this code.1234; +No type information for this code.12345; +No type information for this code.123456; +No type information for this code.1234567; +No type information for this code.12345678; +No type information for this code.123456789; +No type information for this code.1234567890; +No type information for this code.12345678901; +No type information for this code.123456789012; +No type information for this code.1234567890123; +No type information for this code.12345678901234; +No type information for this code.123456789012345; +No type information for this code.1234567890123456; +No type information for this code.12345678901234567; +No type information for this code.123456789012345678; +No type information for this code.1234567890123456789; +No type information for this code.12345678901234567890; +No type information for this code. +No type information for this code.9007199254740989; +No type information for this code.9007199254740990; +No type information for this code.9007199254740991; +No type information for this code.9007199254740992; +No type information for this code.9007199254740993; +No type information for this code. +No type information for this code.0x1; +No type information for this code.0x12; +No type information for this code.0x123; +No type information for this code.0x1234; +No type information for this code.0x12345; +No type information for this code.0x123456; +No type information for this code.0x1234567; +No type information for this code.0x12345678; +No type information for this code.0x123456789; +No type information for this code.0x1234567890; +No type information for this code.0x12345678901; +No type information for this code.0x123456789012; +No type information for this code.0x1234567890123; +No type information for this code.0x12345678901234; +No type information for this code.0x123456789012345; +No type information for this code.0x1234567890123456; +No type information for this code.0x12345678901234567; +No type information for this code.0x123456789012345678; +No type information for this code.0x1234567890123456789; +No type information for this code.0x12345678901234567890; +No type information for this code.0x123456789012345678901; +No type information for this code.0x1234567890123456789012; +No type information for this code.0x12345678901234567890123; +No type information for this code.0x123456789012345678901234; +No type information for this code.0x1234567890123456789012345; +No type information for this code. +No type information for this code.0x19999999999998; +No type information for this code.0x19999999999999; +No type information for this code.0x20000000000000; +No type information for this code.0x20000000000001; +No type information for this code.0x20000000000002; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/impreciseNumericLiterals.types b/tests/baselines/reference/impreciseNumericLiterals.types new file mode 100644 index 0000000000000..94474d9728396 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.types @@ -0,0 +1,166 @@ +=== tests/cases/compiler/impreciseNumericLiterals.ts === +1; +>1 : 1 + +12; +>12 : 12 + +123; +>123 : 123 + +1234; +>1234 : 1234 + +12345; +>12345 : 12345 + +123456; +>123456 : 123456 + +1234567; +>1234567 : 1234567 + +12345678; +>12345678 : 12345678 + +123456789; +>123456789 : 123456789 + +1234567890; +>1234567890 : 1234567890 + +12345678901; +>12345678901 : 12345678901 + +123456789012; +>123456789012 : 123456789012 + +1234567890123; +>1234567890123 : 1234567890123 + +12345678901234; +>12345678901234 : 12345678901234 + +123456789012345; +>123456789012345 : 123456789012345 + +1234567890123456; +>1234567890123456 : 1234567890123456 + +12345678901234567; +>12345678901234567 : 12345678901234568 + +123456789012345678; +>123456789012345678 : 123456789012345680 + +1234567890123456789; +>1234567890123456789 : 1234567890123456800 + +12345678901234567890; +>12345678901234567890 : 12345678901234567000 + +9007199254740989; +>9007199254740989 : 9007199254740989 + +9007199254740990; +>9007199254740990 : 9007199254740990 + +9007199254740991; +>9007199254740991 : 9007199254740991 + +9007199254740992; +>9007199254740992 : 9007199254740992 + +9007199254740993; +>9007199254740993 : 9007199254740992 + +0x1; +>0x1 : 1 + +0x12; +>0x12 : 18 + +0x123; +>0x123 : 291 + +0x1234; +>0x1234 : 4660 + +0x12345; +>0x12345 : 74565 + +0x123456; +>0x123456 : 1193046 + +0x1234567; +>0x1234567 : 19088743 + +0x12345678; +>0x12345678 : 305419896 + +0x123456789; +>0x123456789 : 4886718345 + +0x1234567890; +>0x1234567890 : 78187493520 + +0x12345678901; +>0x12345678901 : 1250999896321 + +0x123456789012; +>0x123456789012 : 20015998341138 + +0x1234567890123; +>0x1234567890123 : 320255973458211 + +0x12345678901234; +>0x12345678901234 : 5124095575331380 + +0x123456789012345; +>0x123456789012345 : 81985529205302080 + +0x1234567890123456; +>0x1234567890123456 : 1311768467284833300 + +0x12345678901234567; +>0x12345678901234567 : 20988295476557332000 + +0x123456789012345678; +>0x123456789012345678 : 335812727624917300000 + +0x1234567890123456789; +>0x1234567890123456789 : 5.373003641998677e+21 + +0x12345678901234567890; +>0x12345678901234567890 : 8.596805827197883e+22 + +0x123456789012345678901; +>0x123456789012345678901 : 1.3754889323516613e+24 + +0x1234567890123456789012; +>0x1234567890123456789012 : 2.200782291762658e+25 + +0x12345678901234567890123; +>0x12345678901234567890123 : 3.521251666820253e+26 + +0x123456789012345678901234; +>0x123456789012345678901234 : 5.634002666912405e+27 + +0x1234567890123456789012345; +>0x1234567890123456789012345 : 9.014404267059848e+28 + +0x19999999999998; +>0x19999999999998 : 7205759403792792 + +0x19999999999999; +>0x19999999999999 : 7205759403792793 + +0x20000000000000; +>0x20000000000000 : 9007199254740992 + +0x20000000000001; +>0x20000000000001 : 9007199254740992 + +0x20000000000002; +>0x20000000000002 : 9007199254740994 + diff --git a/tests/cases/compiler/impreciseNumericLiterals.ts b/tests/cases/compiler/impreciseNumericLiterals.ts new file mode 100644 index 0000000000000..dbf5ec7f3981d --- /dev/null +++ b/tests/cases/compiler/impreciseNumericLiterals.ts @@ -0,0 +1,58 @@ +1; +12; +123; +1234; +12345; +123456; +1234567; +12345678; +123456789; +1234567890; +12345678901; +123456789012; +1234567890123; +12345678901234; +123456789012345; +1234567890123456; +12345678901234567; +123456789012345678; +1234567890123456789; +12345678901234567890; + +9007199254740989; +9007199254740990; +9007199254740991; +9007199254740992; +9007199254740993; + +0x1; +0x12; +0x123; +0x1234; +0x12345; +0x123456; +0x1234567; +0x12345678; +0x123456789; +0x1234567890; +0x12345678901; +0x123456789012; +0x1234567890123; +0x12345678901234; +0x123456789012345; +0x1234567890123456; +0x12345678901234567; +0x123456789012345678; +0x1234567890123456789; +0x12345678901234567890; +0x123456789012345678901; +0x1234567890123456789012; +0x12345678901234567890123; +0x123456789012345678901234; +0x1234567890123456789012345; + +0x19999999999998; +0x19999999999999; +0x20000000000000; +0x20000000000001; +0x20000000000002; \ No newline at end of file From ccb7f93ee15cfceb6817e7449960d545337f41a2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 3 Sep 2019 00:51:53 -0400 Subject: [PATCH 2/4] Updated constEnumErrors.errors.txt --- tests/baselines/reference/constEnumErrors.errors.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index 0d278197c9bf5..4f3fb4b3da6fb 100644 --- a/tests/baselines/reference/constEnumErrors.errors.txt +++ b/tests/baselines/reference/constEnumErrors.errors.txt @@ -8,12 +8,13 @@ tests/cases/compiler/constEnumErrors.ts(24,13): error TS2476: A const enum membe tests/cases/compiler/constEnumErrors.ts(26,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. tests/cases/compiler/constEnumErrors.ts(27,10): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. tests/cases/compiler/constEnumErrors.ts(32,5): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. +tests/cases/compiler/constEnumErrors.ts(35,9): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. tests/cases/compiler/constEnumErrors.ts(40,9): error TS2477: 'const' enum member initializer was evaluated to a non-finite value. tests/cases/compiler/constEnumErrors.ts(41,9): error TS2477: 'const' enum member initializer was evaluated to a non-finite value. tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member initializer was evaluated to disallowed value 'NaN'. -==== tests/cases/compiler/constEnumErrors.ts (13 errors) ==== +==== tests/cases/compiler/constEnumErrors.ts (14 errors) ==== const enum E { ~ !!! error TS2567: Enum declarations can only merge with namespace or other enum declarations. @@ -69,6 +70,8 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member const enum NaNOrInfinity { A = 9007199254740992, + ~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. B = A * A, C = B * B, D = C * C, From 59f697a27f38873492f6798869359f16f1f5470b Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 3 Sep 2019 01:08:11 -0400 Subject: [PATCH 3/4] Always with the TSLint... --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fbc5fff7fef86..624b1d87662ee 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33676,11 +33676,11 @@ namespace ts { diagnosticMessage = Diagnostics.Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0; } } - + if (!diagnosticMessage && numericLiteralValueImpreciselyLarge(node.text)) { diagnosticMessage = Diagnostics.Numeric_literal_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_an_integer; } - + if (diagnosticMessage) { const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken; const literal = (withMinus ? "-" : "") + "0o" + node.text; @@ -33689,7 +33689,7 @@ namespace ts { return false; } - + function numericLiteralValueImpreciselyLarge(text: string) { // We can quickly bail out in two common cases: // * Literals with 15 or fewer characters, as they aren't long enough to reach 2^53 - 1 From 281e7a461c280852c1a24566718177d8fd7a89c8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 3 Sep 2019 11:15:02 -0400 Subject: [PATCH 4/4] Updated error message to mention negative values; added tests --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../reference/constEnumErrors.errors.txt | 4 +- .../impreciseNumericLiterals.errors.txt | 156 ++++++++++--- .../reference/impreciseNumericLiterals.js | 113 ++++++++- .../impreciseNumericLiterals.symbols | 56 +++++ .../reference/impreciseNumericLiterals.types | 220 ++++++++++++++++++ .../compiler/impreciseNumericLiterals.ts | 57 ++++- 8 files changed, 575 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 624b1d87662ee..30592e18f618f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33678,7 +33678,7 @@ namespace ts { } if (!diagnosticMessage && numericLiteralValueImpreciselyLarge(node.text)) { - diagnosticMessage = Diagnostics.Numeric_literal_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_an_integer; + diagnosticMessage = Diagnostics.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_an_integer; } if (diagnosticMessage) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index bcda838a32cc2..3020d80f94b75 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1035,7 +1035,7 @@ "category": "Error", "code": 1356 }, - "Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer.": { + "Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer.": { "category": "Error", "code": 1357 }, diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index 4f3fb4b3da6fb..5c4530a1284ac 100644 --- a/tests/baselines/reference/constEnumErrors.errors.txt +++ b/tests/baselines/reference/constEnumErrors.errors.txt @@ -8,7 +8,7 @@ tests/cases/compiler/constEnumErrors.ts(24,13): error TS2476: A const enum membe tests/cases/compiler/constEnumErrors.ts(26,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. tests/cases/compiler/constEnumErrors.ts(27,10): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. tests/cases/compiler/constEnumErrors.ts(32,5): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/compiler/constEnumErrors.ts(35,9): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/constEnumErrors.ts(35,9): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. tests/cases/compiler/constEnumErrors.ts(40,9): error TS2477: 'const' enum member initializer was evaluated to a non-finite value. tests/cases/compiler/constEnumErrors.ts(41,9): error TS2477: 'const' enum member initializer was evaluated to a non-finite value. tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member initializer was evaluated to disallowed value 'NaN'. @@ -71,7 +71,7 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member const enum NaNOrInfinity { A = 9007199254740992, ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. B = A * A, C = B * B, D = C * C, diff --git a/tests/baselines/reference/impreciseNumericLiterals.errors.txt b/tests/baselines/reference/impreciseNumericLiterals.errors.txt index 88e39a7b0ed52..1ca0df37283c1 100644 --- a/tests/baselines/reference/impreciseNumericLiterals.errors.txt +++ b/tests/baselines/reference/impreciseNumericLiterals.errors.txt @@ -1,103 +1,201 @@ -tests/cases/compiler/impreciseNumericLiterals.ts(17,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(18,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(19,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(20,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(24,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(25,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(26,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(42,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(43,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(44,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(45,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(56,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(57,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. -tests/cases/compiler/impreciseNumericLiterals.ts(58,1): error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(33,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(34,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(35,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(36,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(37,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(38,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(39,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(40,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(46,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(47,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(48,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(49,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(50,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(51,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(81,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(82,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(83,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(84,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(85,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(86,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(87,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(88,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(108,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(109,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(110,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(111,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(112,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. +tests/cases/compiler/impreciseNumericLiterals.ts(113,1): error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. -==== tests/cases/compiler/impreciseNumericLiterals.ts (14 errors) ==== +==== tests/cases/compiler/impreciseNumericLiterals.ts (28 errors) ==== 1; + -1; 12; + -12; 123; + -123; 1234; + -1234; 12345; + -12345; 123456; + -123456; 1234567; + -1234567; 12345678; + -12345678; 123456789; + -123456789; 1234567890; + -1234567890; 12345678901; + -12345678901; 123456789012; + -123456789012; 1234567890123; + -1234567890123; 12345678901234; + -12345678901234; 123456789012345; + -123456789012345; 1234567890123456; + -1234567890123456; 12345678901234567; ~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -12345678901234567; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 123456789012345678; ~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -123456789012345678; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 1234567890123456789; ~~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -1234567890123456789; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 12345678901234567890; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -12345678901234567890; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 9007199254740989; + -9007199254740989; 9007199254740990; + -9007199254740990; 9007199254740991; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -9007199254740991; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 9007199254740992; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -9007199254740992; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 9007199254740993; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -9007199254740993; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x1; + -0x1; 0x12; + -0x12; 0x123; + -0x123; 0x1234; + -0x1234; 0x12345; + -0x12345; 0x123456; + -0x123456; 0x1234567; + -0x1234567; 0x12345678; + -0x12345678; 0x123456789; + -0x123456789; 0x1234567890; + -0x1234567890; 0x12345678901; + -0x12345678901; 0x123456789012; + -0x123456789012; 0x1234567890123; + -0x1234567890123; 0x12345678901234; + -0x12345678901234; 0x123456789012345; ~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x123456789012345; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x1234567890123456; ~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x1234567890123456; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x12345678901234567; ~~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x12345678901234567; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x123456789012345678; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x123456789012345678; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x1234567890123456789; + -0x1234567890123456789; 0x12345678901234567890; + -0x12345678901234567890; 0x123456789012345678901; + -0x123456789012345678901; 0x1234567890123456789012; + -0x1234567890123456789012; 0x12345678901234567890123; + -0x12345678901234567890123; 0x123456789012345678901234; + -0x123456789012345678901234; 0x1234567890123456789012345; + -0x1234567890123456789012345; 0x19999999999998; + -0x19999999999998; 0x19999999999999; + -0x19999999999999; 0x20000000000000; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x20000000000000; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x20000000000001; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x20000000000001; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. 0x20000000000002; ~~~~~~~~~~~~~~~~ -!!! error TS1357: Numeric literal values equal to 2^53 or greater are too large to be represented accurately as an integer. \ No newline at end of file +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + -0x20000000000002; + ~~~~~~~~~~~~~~~~~ +!!! error TS1357: Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as an integer. + \ No newline at end of file diff --git a/tests/baselines/reference/impreciseNumericLiterals.js b/tests/baselines/reference/impreciseNumericLiterals.js index b7227218108be..d13fc523b5e95 100644 --- a/tests/baselines/reference/impreciseNumericLiterals.js +++ b/tests/baselines/reference/impreciseNumericLiterals.js @@ -1,116 +1,227 @@ //// [impreciseNumericLiterals.ts] 1; +-1; 12; +-12; 123; +-123; 1234; +-1234; 12345; +-12345; 123456; +-123456; 1234567; +-1234567; 12345678; +-12345678; 123456789; +-123456789; 1234567890; +-1234567890; 12345678901; +-12345678901; 123456789012; +-123456789012; 1234567890123; +-1234567890123; 12345678901234; +-12345678901234; 123456789012345; +-123456789012345; 1234567890123456; +-1234567890123456; 12345678901234567; +-12345678901234567; 123456789012345678; +-123456789012345678; 1234567890123456789; +-1234567890123456789; 12345678901234567890; +-12345678901234567890; 9007199254740989; +-9007199254740989; 9007199254740990; +-9007199254740990; 9007199254740991; +-9007199254740991; 9007199254740992; +-9007199254740992; 9007199254740993; +-9007199254740993; 0x1; +-0x1; 0x12; +-0x12; 0x123; +-0x123; 0x1234; +-0x1234; 0x12345; +-0x12345; 0x123456; +-0x123456; 0x1234567; +-0x1234567; 0x12345678; +-0x12345678; 0x123456789; +-0x123456789; 0x1234567890; +-0x1234567890; 0x12345678901; +-0x12345678901; 0x123456789012; +-0x123456789012; 0x1234567890123; +-0x1234567890123; 0x12345678901234; +-0x12345678901234; 0x123456789012345; +-0x123456789012345; 0x1234567890123456; +-0x1234567890123456; 0x12345678901234567; +-0x12345678901234567; 0x123456789012345678; +-0x123456789012345678; 0x1234567890123456789; +-0x1234567890123456789; 0x12345678901234567890; +-0x12345678901234567890; 0x123456789012345678901; +-0x123456789012345678901; 0x1234567890123456789012; +-0x1234567890123456789012; 0x12345678901234567890123; +-0x12345678901234567890123; 0x123456789012345678901234; +-0x123456789012345678901234; 0x1234567890123456789012345; +-0x1234567890123456789012345; 0x19999999999998; +-0x19999999999998; 0x19999999999999; +-0x19999999999999; 0x20000000000000; +-0x20000000000000; 0x20000000000001; -0x20000000000002; +-0x20000000000001; +0x20000000000002; +-0x20000000000002; + //// [impreciseNumericLiterals.js] 1; +-1; 12; +-12; 123; +-123; 1234; +-1234; 12345; +-12345; 123456; +-123456; 1234567; +-1234567; 12345678; +-12345678; 123456789; +-123456789; 1234567890; +-1234567890; 12345678901; +-12345678901; 123456789012; +-123456789012; 1234567890123; +-1234567890123; 12345678901234; +-12345678901234; 123456789012345; +-123456789012345; 1234567890123456; +-1234567890123456; 12345678901234567; +-12345678901234567; 123456789012345678; +-123456789012345678; 1234567890123456789; +-1234567890123456789; 12345678901234567890; +-12345678901234567890; 9007199254740989; +-9007199254740989; 9007199254740990; +-9007199254740990; 9007199254740991; +-9007199254740991; 9007199254740992; +-9007199254740992; 9007199254740993; +-9007199254740993; 0x1; +-0x1; 0x12; +-0x12; 0x123; +-0x123; 0x1234; +-0x1234; 0x12345; +-0x12345; 0x123456; +-0x123456; 0x1234567; +-0x1234567; 0x12345678; +-0x12345678; 0x123456789; +-0x123456789; 0x1234567890; +-0x1234567890; 0x12345678901; +-0x12345678901; 0x123456789012; +-0x123456789012; 0x1234567890123; +-0x1234567890123; 0x12345678901234; +-0x12345678901234; 0x123456789012345; +-0x123456789012345; 0x1234567890123456; +-0x1234567890123456; 0x12345678901234567; +-0x12345678901234567; 0x123456789012345678; +-0x123456789012345678; 0x1234567890123456789; +-0x1234567890123456789; 0x12345678901234567890; +-0x12345678901234567890; 0x123456789012345678901; +-0x123456789012345678901; 0x1234567890123456789012; +-0x1234567890123456789012; 0x12345678901234567890123; +-0x12345678901234567890123; 0x123456789012345678901234; +-0x123456789012345678901234; 0x1234567890123456789012345; +-0x1234567890123456789012345; 0x19999999999998; +-0x19999999999998; 0x19999999999999; +-0x19999999999999; 0x20000000000000; +-0x20000000000000; 0x20000000000001; +-0x20000000000001; 0x20000000000002; +-0x20000000000002; diff --git a/tests/baselines/reference/impreciseNumericLiterals.symbols b/tests/baselines/reference/impreciseNumericLiterals.symbols index 2b3d0c27b5ced..c342ae8423d41 100644 --- a/tests/baselines/reference/impreciseNumericLiterals.symbols +++ b/tests/baselines/reference/impreciseNumericLiterals.symbols @@ -1,60 +1,116 @@ === tests/cases/compiler/impreciseNumericLiterals.ts === 1; +No type information for this code.-1; No type information for this code.12; +No type information for this code.-12; No type information for this code.123; +No type information for this code.-123; No type information for this code.1234; +No type information for this code.-1234; No type information for this code.12345; +No type information for this code.-12345; No type information for this code.123456; +No type information for this code.-123456; No type information for this code.1234567; +No type information for this code.-1234567; No type information for this code.12345678; +No type information for this code.-12345678; No type information for this code.123456789; +No type information for this code.-123456789; No type information for this code.1234567890; +No type information for this code.-1234567890; No type information for this code.12345678901; +No type information for this code.-12345678901; No type information for this code.123456789012; +No type information for this code.-123456789012; No type information for this code.1234567890123; +No type information for this code.-1234567890123; No type information for this code.12345678901234; +No type information for this code.-12345678901234; No type information for this code.123456789012345; +No type information for this code.-123456789012345; No type information for this code.1234567890123456; +No type information for this code.-1234567890123456; No type information for this code.12345678901234567; +No type information for this code.-12345678901234567; No type information for this code.123456789012345678; +No type information for this code.-123456789012345678; No type information for this code.1234567890123456789; +No type information for this code.-1234567890123456789; No type information for this code.12345678901234567890; +No type information for this code.-12345678901234567890; No type information for this code. No type information for this code.9007199254740989; +No type information for this code.-9007199254740989; No type information for this code.9007199254740990; +No type information for this code.-9007199254740990; No type information for this code.9007199254740991; +No type information for this code.-9007199254740991; No type information for this code.9007199254740992; +No type information for this code.-9007199254740992; No type information for this code.9007199254740993; +No type information for this code.-9007199254740993; No type information for this code. No type information for this code.0x1; +No type information for this code.-0x1; No type information for this code.0x12; +No type information for this code.-0x12; No type information for this code.0x123; +No type information for this code.-0x123; No type information for this code.0x1234; +No type information for this code.-0x1234; No type information for this code.0x12345; +No type information for this code.-0x12345; No type information for this code.0x123456; +No type information for this code.-0x123456; No type information for this code.0x1234567; +No type information for this code.-0x1234567; No type information for this code.0x12345678; +No type information for this code.-0x12345678; No type information for this code.0x123456789; +No type information for this code.-0x123456789; No type information for this code.0x1234567890; +No type information for this code.-0x1234567890; No type information for this code.0x12345678901; +No type information for this code.-0x12345678901; No type information for this code.0x123456789012; +No type information for this code.-0x123456789012; No type information for this code.0x1234567890123; +No type information for this code.-0x1234567890123; No type information for this code.0x12345678901234; +No type information for this code.-0x12345678901234; No type information for this code.0x123456789012345; +No type information for this code.-0x123456789012345; No type information for this code.0x1234567890123456; +No type information for this code.-0x1234567890123456; No type information for this code.0x12345678901234567; +No type information for this code.-0x12345678901234567; No type information for this code.0x123456789012345678; +No type information for this code.-0x123456789012345678; No type information for this code.0x1234567890123456789; +No type information for this code.-0x1234567890123456789; No type information for this code.0x12345678901234567890; +No type information for this code.-0x12345678901234567890; No type information for this code.0x123456789012345678901; +No type information for this code.-0x123456789012345678901; No type information for this code.0x1234567890123456789012; +No type information for this code.-0x1234567890123456789012; No type information for this code.0x12345678901234567890123; +No type information for this code.-0x12345678901234567890123; No type information for this code.0x123456789012345678901234; +No type information for this code.-0x123456789012345678901234; No type information for this code.0x1234567890123456789012345; +No type information for this code.-0x1234567890123456789012345; No type information for this code. No type information for this code.0x19999999999998; +No type information for this code.-0x19999999999998; No type information for this code.0x19999999999999; +No type information for this code.-0x19999999999999; No type information for this code.0x20000000000000; +No type information for this code.-0x20000000000000; No type information for this code.0x20000000000001; +No type information for this code.-0x20000000000001; No type information for this code.0x20000000000002; +No type information for this code.-0x20000000000002; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/impreciseNumericLiterals.types b/tests/baselines/reference/impreciseNumericLiterals.types index 94474d9728396..6f07a8a3a0599 100644 --- a/tests/baselines/reference/impreciseNumericLiterals.types +++ b/tests/baselines/reference/impreciseNumericLiterals.types @@ -2,165 +2,385 @@ 1; >1 : 1 +-1; +>-1 : -1 +>1 : 1 + 12; >12 : 12 +-12; +>-12 : -12 +>12 : 12 + 123; >123 : 123 +-123; +>-123 : -123 +>123 : 123 + 1234; >1234 : 1234 +-1234; +>-1234 : -1234 +>1234 : 1234 + 12345; >12345 : 12345 +-12345; +>-12345 : -12345 +>12345 : 12345 + 123456; >123456 : 123456 +-123456; +>-123456 : -123456 +>123456 : 123456 + 1234567; >1234567 : 1234567 +-1234567; +>-1234567 : -1234567 +>1234567 : 1234567 + 12345678; >12345678 : 12345678 +-12345678; +>-12345678 : -12345678 +>12345678 : 12345678 + 123456789; >123456789 : 123456789 +-123456789; +>-123456789 : -123456789 +>123456789 : 123456789 + 1234567890; >1234567890 : 1234567890 +-1234567890; +>-1234567890 : -1234567890 +>1234567890 : 1234567890 + 12345678901; >12345678901 : 12345678901 +-12345678901; +>-12345678901 : -12345678901 +>12345678901 : 12345678901 + 123456789012; >123456789012 : 123456789012 +-123456789012; +>-123456789012 : -123456789012 +>123456789012 : 123456789012 + 1234567890123; >1234567890123 : 1234567890123 +-1234567890123; +>-1234567890123 : -1234567890123 +>1234567890123 : 1234567890123 + 12345678901234; >12345678901234 : 12345678901234 +-12345678901234; +>-12345678901234 : -12345678901234 +>12345678901234 : 12345678901234 + 123456789012345; >123456789012345 : 123456789012345 +-123456789012345; +>-123456789012345 : -123456789012345 +>123456789012345 : 123456789012345 + 1234567890123456; >1234567890123456 : 1234567890123456 +-1234567890123456; +>-1234567890123456 : -1234567890123456 +>1234567890123456 : 1234567890123456 + 12345678901234567; >12345678901234567 : 12345678901234568 +-12345678901234567; +>-12345678901234567 : -12345678901234568 +>12345678901234567 : 12345678901234568 + 123456789012345678; >123456789012345678 : 123456789012345680 +-123456789012345678; +>-123456789012345678 : -123456789012345680 +>123456789012345678 : 123456789012345680 + 1234567890123456789; >1234567890123456789 : 1234567890123456800 +-1234567890123456789; +>-1234567890123456789 : -1234567890123456800 +>1234567890123456789 : 1234567890123456800 + 12345678901234567890; >12345678901234567890 : 12345678901234567000 +-12345678901234567890; +>-12345678901234567890 : -12345678901234567000 +>12345678901234567890 : 12345678901234567000 + 9007199254740989; >9007199254740989 : 9007199254740989 +-9007199254740989; +>-9007199254740989 : -9007199254740989 +>9007199254740989 : 9007199254740989 + 9007199254740990; >9007199254740990 : 9007199254740990 +-9007199254740990; +>-9007199254740990 : -9007199254740990 +>9007199254740990 : 9007199254740990 + 9007199254740991; >9007199254740991 : 9007199254740991 +-9007199254740991; +>-9007199254740991 : -9007199254740991 +>9007199254740991 : 9007199254740991 + 9007199254740992; >9007199254740992 : 9007199254740992 +-9007199254740992; +>-9007199254740992 : -9007199254740992 +>9007199254740992 : 9007199254740992 + 9007199254740993; >9007199254740993 : 9007199254740992 +-9007199254740993; +>-9007199254740993 : -9007199254740992 +>9007199254740993 : 9007199254740992 + 0x1; >0x1 : 1 +-0x1; +>-0x1 : -1 +>0x1 : 1 + 0x12; >0x12 : 18 +-0x12; +>-0x12 : -18 +>0x12 : 18 + 0x123; >0x123 : 291 +-0x123; +>-0x123 : -291 +>0x123 : 291 + 0x1234; >0x1234 : 4660 +-0x1234; +>-0x1234 : -4660 +>0x1234 : 4660 + 0x12345; >0x12345 : 74565 +-0x12345; +>-0x12345 : -74565 +>0x12345 : 74565 + 0x123456; >0x123456 : 1193046 +-0x123456; +>-0x123456 : -1193046 +>0x123456 : 1193046 + 0x1234567; >0x1234567 : 19088743 +-0x1234567; +>-0x1234567 : -19088743 +>0x1234567 : 19088743 + 0x12345678; >0x12345678 : 305419896 +-0x12345678; +>-0x12345678 : -305419896 +>0x12345678 : 305419896 + 0x123456789; >0x123456789 : 4886718345 +-0x123456789; +>-0x123456789 : -4886718345 +>0x123456789 : 4886718345 + 0x1234567890; >0x1234567890 : 78187493520 +-0x1234567890; +>-0x1234567890 : -78187493520 +>0x1234567890 : 78187493520 + 0x12345678901; >0x12345678901 : 1250999896321 +-0x12345678901; +>-0x12345678901 : -1250999896321 +>0x12345678901 : 1250999896321 + 0x123456789012; >0x123456789012 : 20015998341138 +-0x123456789012; +>-0x123456789012 : -20015998341138 +>0x123456789012 : 20015998341138 + 0x1234567890123; >0x1234567890123 : 320255973458211 +-0x1234567890123; +>-0x1234567890123 : -320255973458211 +>0x1234567890123 : 320255973458211 + 0x12345678901234; >0x12345678901234 : 5124095575331380 +-0x12345678901234; +>-0x12345678901234 : -5124095575331380 +>0x12345678901234 : 5124095575331380 + 0x123456789012345; >0x123456789012345 : 81985529205302080 +-0x123456789012345; +>-0x123456789012345 : -81985529205302080 +>0x123456789012345 : 81985529205302080 + 0x1234567890123456; >0x1234567890123456 : 1311768467284833300 +-0x1234567890123456; +>-0x1234567890123456 : -1311768467284833300 +>0x1234567890123456 : 1311768467284833300 + 0x12345678901234567; >0x12345678901234567 : 20988295476557332000 +-0x12345678901234567; +>-0x12345678901234567 : -20988295476557332000 +>0x12345678901234567 : 20988295476557332000 + 0x123456789012345678; >0x123456789012345678 : 335812727624917300000 +-0x123456789012345678; +>-0x123456789012345678 : -335812727624917300000 +>0x123456789012345678 : 335812727624917300000 + 0x1234567890123456789; >0x1234567890123456789 : 5.373003641998677e+21 +-0x1234567890123456789; +>-0x1234567890123456789 : -5.373003641998677e+21 +>0x1234567890123456789 : 5.373003641998677e+21 + 0x12345678901234567890; >0x12345678901234567890 : 8.596805827197883e+22 +-0x12345678901234567890; +>-0x12345678901234567890 : -8.596805827197883e+22 +>0x12345678901234567890 : 8.596805827197883e+22 + 0x123456789012345678901; >0x123456789012345678901 : 1.3754889323516613e+24 +-0x123456789012345678901; +>-0x123456789012345678901 : -1.3754889323516613e+24 +>0x123456789012345678901 : 1.3754889323516613e+24 + 0x1234567890123456789012; >0x1234567890123456789012 : 2.200782291762658e+25 +-0x1234567890123456789012; +>-0x1234567890123456789012 : -2.200782291762658e+25 +>0x1234567890123456789012 : 2.200782291762658e+25 + 0x12345678901234567890123; >0x12345678901234567890123 : 3.521251666820253e+26 +-0x12345678901234567890123; +>-0x12345678901234567890123 : -3.521251666820253e+26 +>0x12345678901234567890123 : 3.521251666820253e+26 + 0x123456789012345678901234; >0x123456789012345678901234 : 5.634002666912405e+27 +-0x123456789012345678901234; +>-0x123456789012345678901234 : -5.634002666912405e+27 +>0x123456789012345678901234 : 5.634002666912405e+27 + 0x1234567890123456789012345; >0x1234567890123456789012345 : 9.014404267059848e+28 +-0x1234567890123456789012345; +>-0x1234567890123456789012345 : -9.014404267059848e+28 +>0x1234567890123456789012345 : 9.014404267059848e+28 + 0x19999999999998; >0x19999999999998 : 7205759403792792 +-0x19999999999998; +>-0x19999999999998 : -7205759403792792 +>0x19999999999998 : 7205759403792792 + 0x19999999999999; >0x19999999999999 : 7205759403792793 +-0x19999999999999; +>-0x19999999999999 : -7205759403792793 +>0x19999999999999 : 7205759403792793 + 0x20000000000000; >0x20000000000000 : 9007199254740992 +-0x20000000000000; +>-0x20000000000000 : -9007199254740992 +>0x20000000000000 : 9007199254740992 + 0x20000000000001; >0x20000000000001 : 9007199254740992 +-0x20000000000001; +>-0x20000000000001 : -9007199254740992 +>0x20000000000001 : 9007199254740992 + 0x20000000000002; >0x20000000000002 : 9007199254740994 +-0x20000000000002; +>-0x20000000000002 : -9007199254740994 +>0x20000000000002 : 9007199254740994 + diff --git a/tests/cases/compiler/impreciseNumericLiterals.ts b/tests/cases/compiler/impreciseNumericLiterals.ts index dbf5ec7f3981d..c84c5fb6389f1 100644 --- a/tests/cases/compiler/impreciseNumericLiterals.ts +++ b/tests/cases/compiler/impreciseNumericLiterals.ts @@ -1,58 +1,113 @@ 1; +-1; 12; +-12; 123; +-123; 1234; +-1234; 12345; +-12345; 123456; +-123456; 1234567; +-1234567; 12345678; +-12345678; 123456789; +-123456789; 1234567890; +-1234567890; 12345678901; +-12345678901; 123456789012; +-123456789012; 1234567890123; +-1234567890123; 12345678901234; +-12345678901234; 123456789012345; +-123456789012345; 1234567890123456; +-1234567890123456; 12345678901234567; +-12345678901234567; 123456789012345678; +-123456789012345678; 1234567890123456789; +-1234567890123456789; 12345678901234567890; +-12345678901234567890; 9007199254740989; +-9007199254740989; 9007199254740990; +-9007199254740990; 9007199254740991; +-9007199254740991; 9007199254740992; +-9007199254740992; 9007199254740993; +-9007199254740993; 0x1; +-0x1; 0x12; +-0x12; 0x123; +-0x123; 0x1234; +-0x1234; 0x12345; +-0x12345; 0x123456; +-0x123456; 0x1234567; +-0x1234567; 0x12345678; +-0x12345678; 0x123456789; +-0x123456789; 0x1234567890; +-0x1234567890; 0x12345678901; +-0x12345678901; 0x123456789012; +-0x123456789012; 0x1234567890123; +-0x1234567890123; 0x12345678901234; +-0x12345678901234; 0x123456789012345; +-0x123456789012345; 0x1234567890123456; +-0x1234567890123456; 0x12345678901234567; +-0x12345678901234567; 0x123456789012345678; +-0x123456789012345678; 0x1234567890123456789; +-0x1234567890123456789; 0x12345678901234567890; +-0x12345678901234567890; 0x123456789012345678901; +-0x123456789012345678901; 0x1234567890123456789012; +-0x1234567890123456789012; 0x12345678901234567890123; +-0x12345678901234567890123; 0x123456789012345678901234; +-0x123456789012345678901234; 0x1234567890123456789012345; +-0x1234567890123456789012345; 0x19999999999998; +-0x19999999999998; 0x19999999999999; +-0x19999999999999; 0x20000000000000; +-0x20000000000000; 0x20000000000001; -0x20000000000002; \ No newline at end of file +-0x20000000000001; +0x20000000000002; +-0x20000000000002;