diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6008bb2da1ffe..a5bcfbd4fa976 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39831,6 +39831,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (leftOk && rightOk) { checkAssignmentOperator(resultType); + switch (operator) { + case SyntaxKind.LessThanLessThanToken: + case SyntaxKind.LessThanLessThanEqualsToken: + case SyntaxKind.GreaterThanGreaterThanToken: + case SyntaxKind.GreaterThanGreaterThanEqualsToken: + case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: + case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken: + const rhsEval = evaluate(right); + if (typeof rhsEval.value === "number" && Math.abs(rhsEval.value) >= 32) { + errorOrSuggestion( + isEnumMember(walkUpParenthesizedExpressions(right.parent.parent)), // elevate from suggestion to error within an enum member + errorNode || operatorToken, + Diagnostics.This_operation_can_be_simplified_This_shift_is_identical_to_0_1_2, + getTextOfNode(left), + tokenToString(operator), + rhsEval.value % 32, + ); + } + break; + default: + break; + } } return resultType; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 850d5ca1022af..36213fbc314e8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6420,6 +6420,10 @@ "category": "Message", "code": 6806 }, + "This operation can be simplified. This shift is identical to `{0} {1} {2}`.": { + "category": "Error", + "code": 6807 + }, "one of:": { "category": "Message", diff --git a/src/harness/compilerImpl.ts b/src/harness/compilerImpl.ts index 90393622d9308..4e19b1443aea3 100644 --- a/src/harness/compilerImpl.ts +++ b/src/harness/compilerImpl.ts @@ -241,7 +241,7 @@ export class CompilationResult { } } -export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions, typeScriptVersion?: string): CompilationResult { +export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions, typeScriptVersion?: string, captureSuggestions?: boolean): CompilationResult { if (compilerOptions.project || !rootFiles || rootFiles.length === 0) { const project = readProject(host.parseConfigHost, compilerOptions.project, compilerOptions); if (project) { @@ -265,11 +265,17 @@ export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | und // and if the test is running `skipLibCheck` - an indicator that we want the tets to run quickly - skip the before/after error comparison, too const skipErrorComparison = ts.length(rootFiles) >= 100 || (!!compilerOptions.skipLibCheck && !!compilerOptions.declaration); const preProgram = !skipErrorComparison ? ts.createProgram({ rootNames: rootFiles || [], options: { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host, typeScriptVersion }) : undefined; - const preErrors = preProgram && ts.getPreEmitDiagnostics(preProgram); + let preErrors = preProgram && ts.getPreEmitDiagnostics(preProgram); + if (preProgram && captureSuggestions) { + preErrors = ts.concatenate(preErrors, ts.flatMap(preProgram.getSourceFiles(), f => preProgram.getSuggestionDiagnostics(f))); + } const program = ts.createProgram({ rootNames: rootFiles || [], options: compilerOptions, host, typeScriptVersion }); const emitResult = program.emit(); - const postErrors = ts.getPreEmitDiagnostics(program); + let postErrors = ts.getPreEmitDiagnostics(program); + if (captureSuggestions) { + postErrors = ts.concatenate(postErrors, ts.flatMap(program.getSourceFiles(), f => program.getSuggestionDiagnostics(f))); + } const longerErrors = ts.length(preErrors) > postErrors.length ? preErrors : postErrors; const shorterErrors = longerErrors === preErrors ? postErrors : preErrors; const errors = preErrors && (preErrors.length !== postErrors.length) ? [ diff --git a/src/harness/harnessIO.ts b/src/harness/harnessIO.ts index e27cf3cf949c0..32b5c1e42811f 100644 --- a/src/harness/harnessIO.ts +++ b/src/harness/harnessIO.ts @@ -282,6 +282,7 @@ export namespace Compiler { baselineFile?: string; libFiles?: string; noTypesAndSymbols?: boolean; + captureSuggestions?: boolean; } // Additional options not already in ts.optionDeclarations @@ -303,6 +304,7 @@ export namespace Compiler { { name: "fullEmitPaths", type: "boolean", defaultValueDescription: false }, { name: "noCheck", type: "boolean", defaultValueDescription: false }, { name: "reportDiagnostics", type: "boolean", defaultValueDescription: false }, // used to enable error collection in `transpile` baselines + { name: "captureSuggestions", type: "boolean", defaultValueDescription: false }, // Adds suggestion diagnostics to error baselines ]; let optionsIndex: Map; @@ -428,7 +430,7 @@ export namespace Compiler { ts.assign(options, ts.convertToOptionsWithAbsolutePaths(options, path => ts.getNormalizedAbsolutePath(path, currentDirectory))); const host = new fakes.CompilerHost(fs, options); - const result = compiler.compileFiles(host, programFileNames, options, typeScriptVersion); + const result = compiler.compileFiles(host, programFileNames, options, typeScriptVersion, harnessSettings?.captureSuggestions === "true"); result.symlinks = symlinks; (result as CompileFilesResult).repeat = newOptions => compileFiles(inputFiles, otherFiles, { ...harnessSettings, ...newOptions }, compilerOptions, originalCurrentDirectory, symlinks); return result as CompileFilesResult; diff --git a/tests/baselines/reference/overshifts.errors.txt b/tests/baselines/reference/overshifts.errors.txt new file mode 100644 index 0000000000000..dde392d2fda17 --- /dev/null +++ b/tests/baselines/reference/overshifts.errors.txt @@ -0,0 +1,253 @@ +overshifts.ts(2,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(3,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 27`. +overshifts.ts(4,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(6,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(7,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << -27`. +overshifts.ts(8,1): suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(11,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(12,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 27`. +overshifts.ts(13,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(15,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(16,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> -27`. +overshifts.ts(17,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(20,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(21,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 27`. +overshifts.ts(22,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(24,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(25,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> -27`. +overshifts.ts(26,1): suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(30,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. +overshifts.ts(31,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 27`. +overshifts.ts(32,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. +overshifts.ts(34,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. +overshifts.ts(35,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= -27`. +overshifts.ts(36,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. +overshifts.ts(39,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. +overshifts.ts(40,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 27`. +overshifts.ts(41,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. +overshifts.ts(43,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. +overshifts.ts(44,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= -27`. +overshifts.ts(45,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. +overshifts.ts(48,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. +overshifts.ts(49,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 27`. +overshifts.ts(50,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. +overshifts.ts(52,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. +overshifts.ts(53,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= -27`. +overshifts.ts(54,1): suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. +overshifts.ts(58,9): error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(59,9): error TS6807: This operation can be simplified. This shift is identical to `1 << 27`. +overshifts.ts(60,9): error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(62,9): error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(63,9): error TS6807: This operation can be simplified. This shift is identical to `1 << -27`. +overshifts.ts(64,9): error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. +overshifts.ts(69,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(70,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 27`. +overshifts.ts(71,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(73,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(74,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> -27`. +overshifts.ts(75,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. +overshifts.ts(80,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(81,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 27`. +overshifts.ts(82,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(84,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. +overshifts.ts(85,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> -27`. +overshifts.ts(86,9): error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + + +==== overshifts.ts (54 errors) ==== + 1 << 1; // ok + 1 << 32; // overshift + ~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + 1 << 123; + ~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 27`. + 1 << 1024; + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + 1 << -1; // OK-ish + 1 << -32; // backwards overshift + ~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + 1 << -123; + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << -27`. + 1 << -1024; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + + 0xFF_FF_FF_FF >> 1; // ok + 0xFF_FF_FF_FF >> 32; // overshift + ~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + 0xFF_FF_FF_FF >> 123; + ~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 27`. + 0xFF_FF_FF_FF >> 1024; + ~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + 0xFF_FF_FF_FF >> -1; // OK-ish + 0xFF_FF_FF_FF >> -32; // backwards overshift + ~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + 0xFF_FF_FF_FF >> -123; + ~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> -27`. + 0xFF_FF_FF_FF >> -1024; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + + 0xFF_FF_FF_FF >>> 1; // ok + 0xFF_FF_FF_FF >>> 32; // overshift + ~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + 0xFF_FF_FF_FF >>> 123; + ~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 27`. + 0xFF_FF_FF_FF >>> 1024; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + 0xFF_FF_FF_FF >>> -1; // OK-ish + 0xFF_FF_FF_FF >>> -32; // backwards overshift + ~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + 0xFF_FF_FF_FF >>> -123; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> -27`. + 0xFF_FF_FF_FF >>> -1024; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + + let x = 1; + x <<= 1; // ok + x <<= 32; // overshift + ~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. + x <<= 123; + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 27`. + x <<= 1024; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. + x <<= -1; // OK-ish + x <<= -32; // backwards overshift + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. + x <<= -123; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= -27`. + x <<= -1024; + ~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x <<= 0`. + + x >>= 1; // ok + x >>= 32; // overshift + ~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. + x >>= 123; + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 27`. + x >>= 1024; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. + x >>= -1; // OK-ish + x >>= -32; // backwards overshift + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. + x >>= -123; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= -27`. + x >>= -1024; + ~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>= 0`. + + x >>>= 1; // ok + x >>>= 32; // overshift + ~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. + x >>>= 123; + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 27`. + x >>>= 1024; + ~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. + x >>>= -1; // OK-ish + x >>>= -32; // backwards overshift + ~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. + x >>>= -123; + ~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= -27`. + x >>>= -1024; + ~~~~~~~~~~~~ +!!! suggestion TS6807: This operation can be simplified. This shift is identical to `x >>>= 0`. + + enum One { + A = 1 << 1, // ok + B = 1 << 32, // overshift + ~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + C = 1 << 123, + ~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << 27`. + D = 1 << 1024, + ~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + E = 1 << -1, // OK-ish + F = 1 << -32, // backwards overshift + ~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + G = 1 << -123, + ~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << -27`. + H = 1 << -1024, + ~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `1 << 0`. + } + + enum Two { + A = 0xFF_FF_FF_FF >> 1, // ok + B = 0xFF_FF_FF_FF >> 32, // overshift + ~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + C = 0xFF_FF_FF_FF >> 123, + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 27`. + D = 0xFF_FF_FF_FF >> 1024, + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + E = 0xFF_FF_FF_FF >> -1, // OK-ish + F = 0xFF_FF_FF_FF >> -32, // backwards overshift + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + G = 0xFF_FF_FF_FF >> -123, + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> -27`. + H = 0xFF_FF_FF_FF >> -1024, + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >> 0`. + } + + enum Three { + A = 0xFF_FF_FF_FF >>> 1, // ok + B = 0xFF_FF_FF_FF >>> 32, // overshift + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + C = 0xFF_FF_FF_FF >>> 123, + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 27`. + D = 0xFF_FF_FF_FF >>> 1024, + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + E = 0xFF_FF_FF_FF >>> -1, // OK-ish + F = 0xFF_FF_FF_FF >>> -32, // backwards overshift + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + G = 0xFF_FF_FF_FF >>> -123, + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> -27`. + H = 0xFF_FF_FF_FF >>> -1024, + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6807: This operation can be simplified. This shift is identical to `0xFF_FF_FF_FF >>> 0`. + } + \ No newline at end of file diff --git a/tests/baselines/reference/overshifts.js b/tests/baselines/reference/overshifts.js new file mode 100644 index 0000000000000..4fec6ff6101e8 --- /dev/null +++ b/tests/baselines/reference/overshifts.js @@ -0,0 +1,175 @@ +//// [tests/cases/compiler/overshifts.ts] //// + +//// [overshifts.ts] +1 << 1; // ok +1 << 32; // overshift +1 << 123; +1 << 1024; +1 << -1; // OK-ish +1 << -32; // backwards overshift +1 << -123; +1 << -1024; + +0xFF_FF_FF_FF >> 1; // ok +0xFF_FF_FF_FF >> 32; // overshift +0xFF_FF_FF_FF >> 123; +0xFF_FF_FF_FF >> 1024; +0xFF_FF_FF_FF >> -1; // OK-ish +0xFF_FF_FF_FF >> -32; // backwards overshift +0xFF_FF_FF_FF >> -123; +0xFF_FF_FF_FF >> -1024; + +0xFF_FF_FF_FF >>> 1; // ok +0xFF_FF_FF_FF >>> 32; // overshift +0xFF_FF_FF_FF >>> 123; +0xFF_FF_FF_FF >>> 1024; +0xFF_FF_FF_FF >>> -1; // OK-ish +0xFF_FF_FF_FF >>> -32; // backwards overshift +0xFF_FF_FF_FF >>> -123; +0xFF_FF_FF_FF >>> -1024; + +let x = 1; +x <<= 1; // ok +x <<= 32; // overshift +x <<= 123; +x <<= 1024; +x <<= -1; // OK-ish +x <<= -32; // backwards overshift +x <<= -123; +x <<= -1024; + +x >>= 1; // ok +x >>= 32; // overshift +x >>= 123; +x >>= 1024; +x >>= -1; // OK-ish +x >>= -32; // backwards overshift +x >>= -123; +x >>= -1024; + +x >>>= 1; // ok +x >>>= 32; // overshift +x >>>= 123; +x >>>= 1024; +x >>>= -1; // OK-ish +x >>>= -32; // backwards overshift +x >>>= -123; +x >>>= -1024; + +enum One { + A = 1 << 1, // ok + B = 1 << 32, // overshift + C = 1 << 123, + D = 1 << 1024, + E = 1 << -1, // OK-ish + F = 1 << -32, // backwards overshift + G = 1 << -123, + H = 1 << -1024, +} + +enum Two { + A = 0xFF_FF_FF_FF >> 1, // ok + B = 0xFF_FF_FF_FF >> 32, // overshift + C = 0xFF_FF_FF_FF >> 123, + D = 0xFF_FF_FF_FF >> 1024, + E = 0xFF_FF_FF_FF >> -1, // OK-ish + F = 0xFF_FF_FF_FF >> -32, // backwards overshift + G = 0xFF_FF_FF_FF >> -123, + H = 0xFF_FF_FF_FF >> -1024, +} + +enum Three { + A = 0xFF_FF_FF_FF >>> 1, // ok + B = 0xFF_FF_FF_FF >>> 32, // overshift + C = 0xFF_FF_FF_FF >>> 123, + D = 0xFF_FF_FF_FF >>> 1024, + E = 0xFF_FF_FF_FF >>> -1, // OK-ish + F = 0xFF_FF_FF_FF >>> -32, // backwards overshift + G = 0xFF_FF_FF_FF >>> -123, + H = 0xFF_FF_FF_FF >>> -1024, +} + + +//// [overshifts.js] +1 << 1; // ok +1 << 32; // overshift +1 << 123; +1 << 1024; +1 << -1; // OK-ish +1 << -32; // backwards overshift +1 << -123; +1 << -1024; +4294967295 >> 1; // ok +4294967295 >> 32; // overshift +4294967295 >> 123; +4294967295 >> 1024; +4294967295 >> -1; // OK-ish +4294967295 >> -32; // backwards overshift +4294967295 >> -123; +4294967295 >> -1024; +4294967295 >>> 1; // ok +4294967295 >>> 32; // overshift +4294967295 >>> 123; +4294967295 >>> 1024; +4294967295 >>> -1; // OK-ish +4294967295 >>> -32; // backwards overshift +4294967295 >>> -123; +4294967295 >>> -1024; +var x = 1; +x <<= 1; // ok +x <<= 32; // overshift +x <<= 123; +x <<= 1024; +x <<= -1; // OK-ish +x <<= -32; // backwards overshift +x <<= -123; +x <<= -1024; +x >>= 1; // ok +x >>= 32; // overshift +x >>= 123; +x >>= 1024; +x >>= -1; // OK-ish +x >>= -32; // backwards overshift +x >>= -123; +x >>= -1024; +x >>>= 1; // ok +x >>>= 32; // overshift +x >>>= 123; +x >>>= 1024; +x >>>= -1; // OK-ish +x >>>= -32; // backwards overshift +x >>>= -123; +x >>>= -1024; +var One; +(function (One) { + One[One["A"] = 2] = "A"; + One[One["B"] = 1] = "B"; + One[One["C"] = 134217728] = "C"; + One[One["D"] = 1] = "D"; + One[One["E"] = -2147483648] = "E"; + One[One["F"] = 1] = "F"; + One[One["G"] = 32] = "G"; + One[One["H"] = 1] = "H"; +})(One || (One = {})); +var Two; +(function (Two) { + Two[Two["A"] = -1] = "A"; + Two[Two["B"] = -1] = "B"; + Two[Two["C"] = -1] = "C"; + Two[Two["D"] = -1] = "D"; + Two[Two["E"] = -1] = "E"; + Two[Two["F"] = -1] = "F"; + Two[Two["G"] = -1] = "G"; + Two[Two["H"] = -1] = "H"; +})(Two || (Two = {})); +var Three; +(function (Three) { + Three[Three["A"] = 2147483647] = "A"; + Three[Three["B"] = 4294967295] = "B"; + Three[Three["C"] = 31] = "C"; + Three[Three["D"] = 4294967295] = "D"; + Three[Three["E"] = 1] = "E"; + Three[Three["F"] = 4294967295] = "F"; + Three[Three["G"] = 134217727] = "G"; + Three[Three["H"] = 4294967295] = "H"; +})(Three || (Three = {})); diff --git a/tests/baselines/reference/overshifts.symbols b/tests/baselines/reference/overshifts.symbols new file mode 100644 index 0000000000000..c961b941e6ee9 --- /dev/null +++ b/tests/baselines/reference/overshifts.symbols @@ -0,0 +1,189 @@ +//// [tests/cases/compiler/overshifts.ts] //// + +=== overshifts.ts === +1 << 1; // ok +1 << 32; // overshift +1 << 123; +1 << 1024; +1 << -1; // OK-ish +1 << -32; // backwards overshift +1 << -123; +1 << -1024; + +0xFF_FF_FF_FF >> 1; // ok +0xFF_FF_FF_FF >> 32; // overshift +0xFF_FF_FF_FF >> 123; +0xFF_FF_FF_FF >> 1024; +0xFF_FF_FF_FF >> -1; // OK-ish +0xFF_FF_FF_FF >> -32; // backwards overshift +0xFF_FF_FF_FF >> -123; +0xFF_FF_FF_FF >> -1024; + +0xFF_FF_FF_FF >>> 1; // ok +0xFF_FF_FF_FF >>> 32; // overshift +0xFF_FF_FF_FF >>> 123; +0xFF_FF_FF_FF >>> 1024; +0xFF_FF_FF_FF >>> -1; // OK-ish +0xFF_FF_FF_FF >>> -32; // backwards overshift +0xFF_FF_FF_FF >>> -123; +0xFF_FF_FF_FF >>> -1024; + +let x = 1; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= 1; // ok +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= 32; // overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= 123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= 1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= -1; // OK-ish +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= -32; // backwards overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= -123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x <<= -1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= 1; // ok +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= 32; // overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= 123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= 1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= -1; // OK-ish +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= -32; // backwards overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= -123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>= -1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= 1; // ok +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= 32; // overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= 123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= 1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= -1; // OK-ish +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= -32; // backwards overshift +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= -123; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +x >>>= -1024; +>x : Symbol(x, Decl(overshifts.ts, 27, 3)) + +enum One { +>One : Symbol(One, Decl(overshifts.ts, 53, 13)) + + A = 1 << 1, // ok +>A : Symbol(One.A, Decl(overshifts.ts, 55, 10)) + + B = 1 << 32, // overshift +>B : Symbol(One.B, Decl(overshifts.ts, 56, 15)) + + C = 1 << 123, +>C : Symbol(One.C, Decl(overshifts.ts, 57, 16)) + + D = 1 << 1024, +>D : Symbol(One.D, Decl(overshifts.ts, 58, 17)) + + E = 1 << -1, // OK-ish +>E : Symbol(One.E, Decl(overshifts.ts, 59, 18)) + + F = 1 << -32, // backwards overshift +>F : Symbol(One.F, Decl(overshifts.ts, 60, 16)) + + G = 1 << -123, +>G : Symbol(One.G, Decl(overshifts.ts, 61, 17)) + + H = 1 << -1024, +>H : Symbol(One.H, Decl(overshifts.ts, 62, 18)) +} + +enum Two { +>Two : Symbol(Two, Decl(overshifts.ts, 64, 1)) + + A = 0xFF_FF_FF_FF >> 1, // ok +>A : Symbol(Two.A, Decl(overshifts.ts, 66, 10)) + + B = 0xFF_FF_FF_FF >> 32, // overshift +>B : Symbol(Two.B, Decl(overshifts.ts, 67, 27)) + + C = 0xFF_FF_FF_FF >> 123, +>C : Symbol(Two.C, Decl(overshifts.ts, 68, 28)) + + D = 0xFF_FF_FF_FF >> 1024, +>D : Symbol(Two.D, Decl(overshifts.ts, 69, 29)) + + E = 0xFF_FF_FF_FF >> -1, // OK-ish +>E : Symbol(Two.E, Decl(overshifts.ts, 70, 30)) + + F = 0xFF_FF_FF_FF >> -32, // backwards overshift +>F : Symbol(Two.F, Decl(overshifts.ts, 71, 28)) + + G = 0xFF_FF_FF_FF >> -123, +>G : Symbol(Two.G, Decl(overshifts.ts, 72, 29)) + + H = 0xFF_FF_FF_FF >> -1024, +>H : Symbol(Two.H, Decl(overshifts.ts, 73, 30)) +} + +enum Three { +>Three : Symbol(Three, Decl(overshifts.ts, 75, 1)) + + A = 0xFF_FF_FF_FF >>> 1, // ok +>A : Symbol(Three.A, Decl(overshifts.ts, 77, 12)) + + B = 0xFF_FF_FF_FF >>> 32, // overshift +>B : Symbol(Three.B, Decl(overshifts.ts, 78, 28)) + + C = 0xFF_FF_FF_FF >>> 123, +>C : Symbol(Three.C, Decl(overshifts.ts, 79, 29)) + + D = 0xFF_FF_FF_FF >>> 1024, +>D : Symbol(Three.D, Decl(overshifts.ts, 80, 30)) + + E = 0xFF_FF_FF_FF >>> -1, // OK-ish +>E : Symbol(Three.E, Decl(overshifts.ts, 81, 31)) + + F = 0xFF_FF_FF_FF >>> -32, // backwards overshift +>F : Symbol(Three.F, Decl(overshifts.ts, 82, 29)) + + G = 0xFF_FF_FF_FF >>> -123, +>G : Symbol(Three.G, Decl(overshifts.ts, 83, 30)) + + H = 0xFF_FF_FF_FF >>> -1024, +>H : Symbol(Three.H, Decl(overshifts.ts, 84, 31)) +} + diff --git a/tests/baselines/reference/overshifts.types b/tests/baselines/reference/overshifts.types new file mode 100644 index 0000000000000..1ca923382065c --- /dev/null +++ b/tests/baselines/reference/overshifts.types @@ -0,0 +1,720 @@ +//// [tests/cases/compiler/overshifts.ts] //// + +=== overshifts.ts === +1 << 1; // ok +>1 << 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +1 << 32; // overshift +>1 << 32 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>32 : 32 +> : ^^ + +1 << 123; +>1 << 123 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>123 : 123 +> : ^^^ + +1 << 1024; +>1 << 1024 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1024 : 1024 +> : ^^^^ + +1 << -1; // OK-ish +>1 << -1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +1 << -32; // backwards overshift +>1 << -32 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +1 << -123; +>1 << -123 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +1 << -1024; +>1 << -1024 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +0xFF_FF_FF_FF >> 1; // ok +>0xFF_FF_FF_FF >> 1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1 : 1 +> : ^ + +0xFF_FF_FF_FF >> 32; // overshift +>0xFF_FF_FF_FF >> 32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>32 : 32 +> : ^^ + +0xFF_FF_FF_FF >> 123; +>0xFF_FF_FF_FF >> 123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>123 : 123 +> : ^^^ + +0xFF_FF_FF_FF >> 1024; +>0xFF_FF_FF_FF >> 1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1024 : 1024 +> : ^^^^ + +0xFF_FF_FF_FF >> -1; // OK-ish +>0xFF_FF_FF_FF >> -1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +0xFF_FF_FF_FF >> -32; // backwards overshift +>0xFF_FF_FF_FF >> -32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +0xFF_FF_FF_FF >> -123; +>0xFF_FF_FF_FF >> -123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +0xFF_FF_FF_FF >> -1024; +>0xFF_FF_FF_FF >> -1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +0xFF_FF_FF_FF >>> 1; // ok +>0xFF_FF_FF_FF >>> 1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1 : 1 +> : ^ + +0xFF_FF_FF_FF >>> 32; // overshift +>0xFF_FF_FF_FF >>> 32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>32 : 32 +> : ^^ + +0xFF_FF_FF_FF >>> 123; +>0xFF_FF_FF_FF >>> 123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>123 : 123 +> : ^^^ + +0xFF_FF_FF_FF >>> 1024; +>0xFF_FF_FF_FF >>> 1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1024 : 1024 +> : ^^^^ + +0xFF_FF_FF_FF >>> -1; // OK-ish +>0xFF_FF_FF_FF >>> -1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +0xFF_FF_FF_FF >>> -32; // backwards overshift +>0xFF_FF_FF_FF >>> -32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +0xFF_FF_FF_FF >>> -123; +>0xFF_FF_FF_FF >>> -123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +0xFF_FF_FF_FF >>> -1024; +>0xFF_FF_FF_FF >>> -1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +let x = 1; +>x : number +> : ^^^^^^ +>1 : 1 +> : ^ + +x <<= 1; // ok +>x <<= 1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1 : 1 +> : ^ + +x <<= 32; // overshift +>x <<= 32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>32 : 32 +> : ^^ + +x <<= 123; +>x <<= 123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +x <<= 1024; +>x <<= 1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1024 : 1024 +> : ^^^^ + +x <<= -1; // OK-ish +>x <<= -1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +x <<= -32; // backwards overshift +>x <<= -32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +x <<= -123; +>x <<= -123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +x <<= -1024; +>x <<= -1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +x >>= 1; // ok +>x >>= 1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1 : 1 +> : ^ + +x >>= 32; // overshift +>x >>= 32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>32 : 32 +> : ^^ + +x >>= 123; +>x >>= 123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +x >>= 1024; +>x >>= 1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1024 : 1024 +> : ^^^^ + +x >>= -1; // OK-ish +>x >>= -1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +x >>= -32; // backwards overshift +>x >>= -32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +x >>= -123; +>x >>= -123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +x >>= -1024; +>x >>= -1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +x >>>= 1; // ok +>x >>>= 1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1 : 1 +> : ^ + +x >>>= 32; // overshift +>x >>>= 32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>32 : 32 +> : ^^ + +x >>>= 123; +>x >>>= 123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +x >>>= 1024; +>x >>>= 1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>1024 : 1024 +> : ^^^^ + +x >>>= -1; // OK-ish +>x >>>= -1 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +x >>>= -32; // backwards overshift +>x >>>= -32 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + +x >>>= -123; +>x >>>= -123 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + +x >>>= -1024; +>x >>>= -1024 : number +> : ^^^^^^ +>x : number +> : ^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ + +enum One { +>One : One +> : ^^^ + + A = 1 << 1, // ok +>A : One.A +> : ^^^^^ +>1 << 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + B = 1 << 32, // overshift +>B : One.B +> : ^^^^^ +>1 << 32 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>32 : 32 +> : ^^ + + C = 1 << 123, +>C : One.C +> : ^^^^^ +>1 << 123 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>123 : 123 +> : ^^^ + + D = 1 << 1024, +>D : One.B +> : ^^^^^ +>1 << 1024 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1024 : 1024 +> : ^^^^ + + E = 1 << -1, // OK-ish +>E : One.E +> : ^^^^^ +>1 << -1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + F = 1 << -32, // backwards overshift +>F : One.B +> : ^^^^^ +>1 << -32 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + + G = 1 << -123, +>G : One.G +> : ^^^^^ +>1 << -123 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + + H = 1 << -1024, +>H : One.B +> : ^^^^^ +>1 << -1024 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ +} + +enum Two { +>Two : Two +> : ^^^ + + A = 0xFF_FF_FF_FF >> 1, // ok +>A : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> 1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1 : 1 +> : ^ + + B = 0xFF_FF_FF_FF >> 32, // overshift +>B : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> 32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>32 : 32 +> : ^^ + + C = 0xFF_FF_FF_FF >> 123, +>C : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> 123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>123 : 123 +> : ^^^ + + D = 0xFF_FF_FF_FF >> 1024, +>D : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> 1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1024 : 1024 +> : ^^^^ + + E = 0xFF_FF_FF_FF >> -1, // OK-ish +>E : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> -1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + F = 0xFF_FF_FF_FF >> -32, // backwards overshift +>F : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> -32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + + G = 0xFF_FF_FF_FF >> -123, +>G : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> -123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + + H = 0xFF_FF_FF_FF >> -1024, +>H : Two.A +> : ^^^^^ +>0xFF_FF_FF_FF >> -1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ +} + +enum Three { +>Three : Three +> : ^^^^^ + + A = 0xFF_FF_FF_FF >>> 1, // ok +>A : Three.A +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> 1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1 : 1 +> : ^ + + B = 0xFF_FF_FF_FF >>> 32, // overshift +>B : Three.B +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> 32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>32 : 32 +> : ^^ + + C = 0xFF_FF_FF_FF >>> 123, +>C : Three.C +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> 123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>123 : 123 +> : ^^^ + + D = 0xFF_FF_FF_FF >>> 1024, +>D : Three.B +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> 1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>1024 : 1024 +> : ^^^^ + + E = 0xFF_FF_FF_FF >>> -1, // OK-ish +>E : Three.E +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> -1 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + F = 0xFF_FF_FF_FF >>> -32, // backwards overshift +>F : Three.B +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> -32 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-32 : -32 +> : ^^^ +>32 : 32 +> : ^^ + + G = 0xFF_FF_FF_FF >>> -123, +>G : Three.G +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> -123 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-123 : -123 +> : ^^^^ +>123 : 123 +> : ^^^ + + H = 0xFF_FF_FF_FF >>> -1024, +>H : Three.B +> : ^^^^^^^ +>0xFF_FF_FF_FF >>> -1024 : number +> : ^^^^^^ +>0xFF_FF_FF_FF : 4294967295 +> : ^^^^^^^^^^ +>-1024 : -1024 +> : ^^^^^ +>1024 : 1024 +> : ^^^^ +} + diff --git a/tests/cases/compiler/overshifts.ts b/tests/cases/compiler/overshifts.ts new file mode 100644 index 0000000000000..fdb22abb1f990 --- /dev/null +++ b/tests/cases/compiler/overshifts.ts @@ -0,0 +1,89 @@ +// @captureSuggestions: true + +1 << 1; // ok +1 << 32; // overshift +1 << 123; +1 << 1024; +1 << -1; // OK-ish +1 << -32; // backwards overshift +1 << -123; +1 << -1024; + +0xFF_FF_FF_FF >> 1; // ok +0xFF_FF_FF_FF >> 32; // overshift +0xFF_FF_FF_FF >> 123; +0xFF_FF_FF_FF >> 1024; +0xFF_FF_FF_FF >> -1; // OK-ish +0xFF_FF_FF_FF >> -32; // backwards overshift +0xFF_FF_FF_FF >> -123; +0xFF_FF_FF_FF >> -1024; + +0xFF_FF_FF_FF >>> 1; // ok +0xFF_FF_FF_FF >>> 32; // overshift +0xFF_FF_FF_FF >>> 123; +0xFF_FF_FF_FF >>> 1024; +0xFF_FF_FF_FF >>> -1; // OK-ish +0xFF_FF_FF_FF >>> -32; // backwards overshift +0xFF_FF_FF_FF >>> -123; +0xFF_FF_FF_FF >>> -1024; + +let x = 1; +x <<= 1; // ok +x <<= 32; // overshift +x <<= 123; +x <<= 1024; +x <<= -1; // OK-ish +x <<= -32; // backwards overshift +x <<= -123; +x <<= -1024; + +x >>= 1; // ok +x >>= 32; // overshift +x >>= 123; +x >>= 1024; +x >>= -1; // OK-ish +x >>= -32; // backwards overshift +x >>= -123; +x >>= -1024; + +x >>>= 1; // ok +x >>>= 32; // overshift +x >>>= 123; +x >>>= 1024; +x >>>= -1; // OK-ish +x >>>= -32; // backwards overshift +x >>>= -123; +x >>>= -1024; + +enum One { + A = 1 << 1, // ok + B = 1 << 32, // overshift + C = 1 << 123, + D = 1 << 1024, + E = 1 << -1, // OK-ish + F = 1 << -32, // backwards overshift + G = 1 << -123, + H = 1 << -1024, +} + +enum Two { + A = 0xFF_FF_FF_FF >> 1, // ok + B = 0xFF_FF_FF_FF >> 32, // overshift + C = 0xFF_FF_FF_FF >> 123, + D = 0xFF_FF_FF_FF >> 1024, + E = 0xFF_FF_FF_FF >> -1, // OK-ish + F = 0xFF_FF_FF_FF >> -32, // backwards overshift + G = 0xFF_FF_FF_FF >> -123, + H = 0xFF_FF_FF_FF >> -1024, +} + +enum Three { + A = 0xFF_FF_FF_FF >>> 1, // ok + B = 0xFF_FF_FF_FF >>> 32, // overshift + C = 0xFF_FF_FF_FF >>> 123, + D = 0xFF_FF_FF_FF >>> 1024, + E = 0xFF_FF_FF_FF >>> -1, // OK-ish + F = 0xFF_FF_FF_FF >>> -32, // backwards overshift + G = 0xFF_FF_FF_FF >>> -123, + H = 0xFF_FF_FF_FF >>> -1024, +}