Repository navigation
Type a shift as its left operand [patch] - #460
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
StaticType typed every non-comparison binary as the wider of its operands, shifts included, so int << long was taken for a long: Go and Rust skipped the widening a long receiver needs and failed to build, and JavaScript ran a chained int shift in 64 bits. A shift now has its left operand's type, the rule the binary and assignment widening paths already follow. Fixes #362 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW4VpqLXsf6UDQnX46h
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #362
What changed
StandardLanguageGenerator.StaticTypetyped every non-comparisonBinaryExpressionasPromoted(left, right), and that included<<and>>. In every target, a shift has the type of its left operand. That rule is already followed byJavaScriptGenerator.IntegerWidthOfand by the binary and assignment widening paths, which exclude shifts.StaticTypenow returnsStaticType(shift.Left)forLeftShiftandRightShift.Effects, with
int bandlong n:var s = b << n; return s;in alongfunctionvar s int64 = (b << n), fails to builds := (b << n)…return int64(s)return b >> n;in alongfunctionreturn int64((b >> n))return (s as i64);,return ((b >> n) as i64);(x << n) << 31withint x, called as(1, 1)4294967296<<, returns0like C#Tests
NumericWideningTests.Widening()gainsshiftedLocalandshiftedReturn. The fixture is shared, so both are now compiled by the Go and RustMixedNumericWidths_Compiletests, and spelling assertions were added toGo_/Rust_WidensTheNarrowerSide.JavaScript_AShiftByALongStaysInItsLeftOperandsWidthruns the generated module under node and checks thatchained(1, 1) === 0.cannot use (b << n) (value of type int) as int64 value,E0308), the two spelling tests and the JavaScript run.Generated by Claude Code