Skip to content

Commit 9158ace

Browse files
authored
fix >> (signed right shift) on Lua 5.3+ (#1720) (#1721)
* fix >> (signed right shift) producing wrong results on Lua 5.3+ * remove dead >> cases and add >>= execution tests * mask shift amount to 5 bits for >> on lua 5.3+ * Revert "fix >> (signed right shift) producing wrong results on Lua 5.3+" This reverts commit 2592ff2. * reword unsupported >> diagnostic
1 parent 979bebe commit 9158ace

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/transformation/utils/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const unsupportedAccessorInObjectLiteral = createErrorDiagnosticFactory(
8282
);
8383

8484
export const unsupportedRightShiftOperator = createErrorDiagnosticFactory(
85-
"Right shift operator is not supported for target Lua 5.3. Use `>>>` instead."
85+
"Signed right shift `>>` is not supported on Lua 5.3+: Lua's native `>>` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use `>>>` if you don't need sign extension, or write your own helper."
8686
);
8787

8888
const getLuaTargetName = (version: LuaTarget) => (version === LuaTarget.LuaJIT ? "LuaJIT" : `Lua ${version}`);

test/unit/__snapshots__/expressions.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,15 @@ ____exports.__result = a
756756
return ____exports"
757757
`;
758758
759-
exports[`Unsupported bitop 5.3 ("a>>=b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;
759+
exports[`Unsupported bitop 5.3 ("a>>=b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Signed right shift \`>>\` is not supported on Lua 5.3+: Lua's native \`>>\` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use \`>>>\` if you don't need sign extension, or write your own helper."`;
760760
761761
exports[`Unsupported bitop 5.3 ("a>>b"): code 1`] = `
762762
"local ____exports = {}
763763
____exports.__result = a >> b
764764
return ____exports"
765765
`;
766766
767-
exports[`Unsupported bitop 5.3 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;
767+
exports[`Unsupported bitop 5.3 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Signed right shift \`>>\` is not supported on Lua 5.3+: Lua's native \`>>\` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use \`>>>\` if you don't need sign extension, or write your own helper."`;
768768
769769
exports[`Unsupported bitop 5.4 ("a>>=b"): code 1`] = `
770770
"local ____exports = {}
@@ -773,12 +773,12 @@ ____exports.__result = a
773773
return ____exports"
774774
`;
775775
776-
exports[`Unsupported bitop 5.4 ("a>>=b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;
776+
exports[`Unsupported bitop 5.4 ("a>>=b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Signed right shift \`>>\` is not supported on Lua 5.3+: Lua's native \`>>\` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use \`>>>\` if you don't need sign extension, or write your own helper."`;
777777
778778
exports[`Unsupported bitop 5.4 ("a>>b"): code 1`] = `
779779
"local ____exports = {}
780780
____exports.__result = a >> b
781781
return ____exports"
782782
`;
783783
784-
exports[`Unsupported bitop 5.4 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;
784+
exports[`Unsupported bitop 5.4 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Signed right shift \`>>\` is not supported on Lua 5.3+: Lua's native \`>>\` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use \`>>>\` if you don't need sign extension, or write your own helper."`;

0 commit comments

Comments
 (0)