fix(transpiler): trailing var returns, receiver history reads, switch na fallback - #319
Open
yusufcansehirli wants to merge 1 commit into
Open
yusufcansehirli wants to merge 1 commit into
yusufcansehirli wants to merge 1 commit into
Conversation
…s in receiver chains, na-fallback for unmatched switches - Implicit return: a trailing `var x = expr` is the function's value; keep the declaration and append `return x`. Previously such functions returned undefined and callers crashed on array ops against the result. - Receiver chains: `(arr[2]).get(i)` emitted raw `$$.let.arr[2].get(i)` — indexing the Series wrapper object itself (undefined at runtime). resolveCalleeObject now lowers computed receivers to `$.get(arr, 2)`. - Switch expressions without a default arm return `na` on no-match instead of undefined; tuple-destructuring element reads use optional chaining so unmatched arms resolve to na instead of crashing on `[0]`.
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.
Three codegen fixes (same batch as #318)
All three reproduced with public Library studies running through the engine.
1. A trailing
vardeclaration is not returnedf() => var fibs = array.from(...)returnsundefined: the declaration is emitted but no implicit return is generated, so callers doingf().get(i)crash withCannot read properties of undefined (reading 'get').Fix: keep the declaration (hoisting/series registration) and append an implicit
return <name>.2. History reads in receiver chains stay raw
(arr[2]).get(i)inside an operand emitted$$.let.arr[2].get(i)— a raw bracket on the Series wrapper object (undefined at runtime). The same expression in a ternary consequent lowered correctly to$.get($$.let.arr, 2).get(i).Fix:
resolveCalleeObjectnow lowers computed receivers to$.get(obj, offset);transformOperanddoes the same for bare computed member operands.3. Unmatched switch expression returns
undefinedA discriminated
switchexpression with no matching arm (or no default case) resolved toundefined, crashing tuple destructuring on[0]. Pine semantics:na.Fix: both switch-IIFE generators append a
return na;fallback when there is no default arm, and tuple-destructuring element reads use optional chaining ($.get(temp, 0)?.[n]) so annavalue resolves instead of crashing.Verification
size() == 3); unmatched-switch destructure runs; operand history read yields a finite number (no NaN).tests/transpiler/— 504 tests pass (one snapshot updated for the?.[n]reads).mainin this environment.