fix: parser accepts new MemberExpression per ECMA-262 (#78)#97
Merged
Conversation
Parser previously rejected `new` whose callee wasn't an identifier or
parenthesized expression — including spec-legal forms like `new true`,
`new 1`, `new "abc"`, `new function(){}(...)`, `new ctors[0]()`, and
`new new X()`. This blocked 49 of the 59 tests under
`test/language/expressions/new/` at parse time.
`ParseNewCallee` now consumes any PrimaryExpression and a member-only
chain (`.name`/`[index]`), with explicit recursion for nested `new`.
Argument-list parsing factors out into `ParseNewArgumentList`, picking
up spread support that the spread-err-* test bucket needs.
Type checker no longer hard-throws when the callee static type isn't
a class — for primitives, function expressions, etc. it defers to the
runtime's TypeError-on-non-constructor path (matches the existing
Function/Any branch).
IL emitter: `EmitCalleeExprConstruction` was missing `EmitBoxIfNeeded`
on the callee, so a value-type callee (`new true`) produced invalid IL
that crashed the JIT with a fatal CLR error (0x80131506). Boxing the
callee before storing it to the `object` temp fixes that.
Test262 deltas:
- Interpreted: +30 new passes, 0 regressions; all 49 ParseError under
`expressions/new/` move off-bucket (29 → Pass, 20 → TypeCheckError).
- Compiled: same 49 move off-bucket (14 Pass, 14 RuntimeError, 29
TypeCheckError, 2 Fail).
Adds 9 parser unit tests covering the new shapes.
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.
Closes #78.
Summary
ParseNewCalleenow accepts any PrimaryExpression (literals, function/class expressions, identifiers, parenthesized exprs,this) plus a member-only chain (.name,[index]), and handles nestednew. Spread args (new X(...iter)) are parsed via the newParseNewArgumentListhelper.new <non-constructor>).EmitCalleeExprConstructionwas missing a box on the callee, sonew trueproduced invalid IL that crashed the JIT (fatal CLR error 0x80131506). One-line fix.Test262 deltas
ParseErrorundertest/language/expressions/new/move off-bucket (29 → Pass, 20 → TypeCheckError on unrelatedSymbol.iteratorlimitation).Both baselines regenerated.
Test plan
dotnet test SharpTS.Tests/SharpTS.Tests.csproj --filter "FullyQualifiedName~ParserTests"— 569 pass