diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfad47b65336f..30592e18f618f 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,15 +33675,32 @@ 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_literals_with_absolute_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) || isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b296c224d089d..3020d80f94b75 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1035,6 +1035,10 @@ "category": "Error", "code": 1356 }, + "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 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index 0d278197c9bf5..5c4530a1284ac 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 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'. -==== 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 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 new file mode 100644 index 0000000000000..1ca0df37283c1 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.errors.txt @@ -0,0 +1,201 @@ +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 (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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 new file mode 100644 index 0000000000000..d13fc523b5e95 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.js @@ -0,0 +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; +-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 new file mode 100644 index 0000000000000..c342ae8423d41 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.symbols @@ -0,0 +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 new file mode 100644 index 0000000000000..6f07a8a3a0599 --- /dev/null +++ b/tests/baselines/reference/impreciseNumericLiterals.types @@ -0,0 +1,386 @@ +=== tests/cases/compiler/impreciseNumericLiterals.ts === +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 new file mode 100644 index 0000000000000..c84c5fb6389f1 --- /dev/null +++ b/tests/cases/compiler/impreciseNumericLiterals.ts @@ -0,0 +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; +-0x20000000000001; +0x20000000000002; +-0x20000000000002;