Repository navigation
Fix parser crash on invalid @as escapes - #9359
Conversation
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Fix parser crash on invalid
|
✅ Compiler benchmarksAllocated wordsIn total: 636,567,697 → 636,561,278 (±0.00%). Generated projects: 629,048,391 → 629,050,446 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,225,369,174 → 9,224,520,504 (-0.01%).
Output sizeIn total: 25,969,863 → 25,969,643 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request ec3592f compared with base 8907cdd in this run. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9359 +/- ##
==========================================
+ Coverage 82.17% 82.19% +0.01%
==========================================
Files 458 459 +1
Lines 65678 65739 +61
==========================================
+ Hits 53971 54031 +60
- Misses 11707 11708 +1
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9359 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Ast_helper read @as payloads with Ast_payload, which raises Location.Error for an invalid escape in a template string. The parser builds fields and constructors with Ast_helper, so the exception escaped from the parser, and res_parser and the editor analysis crashed. Ast_helper now has its own payload readers, which never raise, and leaves such an @as in place for the parser's own diagnostic. This also moves Ast_payload out of the AST library into compiler/ml. Fixes #9351. Diagnostic modified (invalid @as escape): Example: type t = {@as(`\xZZ`) x: int} Before (diagnostic): res_parser -recover Fatal error: exception Location.Error(_) After (diagnostic): res_parser -recover Syntax error! t.res:1:16-19 Invalid string escape sequence Review: Does an @as from a PPX with an invalid escape still get an error? Yes. For a field, Bs_ast_invariant and Record_runtime read the leftover @as with the raising reader. For a constructor, the leftover check now decodes the payload first, so it reports the escape instead of the generic invalid-annotation error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
6684d80 to
ec3592f
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #9351.
An invalid escape in an
@astemplate string, such astype t = {@as(`\xZZ`) x: int}, made the parser throwLocation.Errorinstead of reporting a syntax error.res_parserand the editor analysis (diagnosticSyntax,documentSymbol) crashed;bscreported the error only because its top level catches the exception.The parser builds fields and constructors with
Ast_helper, which read@aswithAst_payload, andAst_payloadraises for an invalid escape.Ast_helpernow has its own payload readers,Ast_helper.Payload, which never raise. An@asit cannot read stays in the attributes, and the parser's own diagnostic reports the escape:bscreports the same message, now as a syntax error, as it already did when the invalid@ascame second.This also takes
Ast_payloadout of the AST library: it moves tocompiler/mland reusesAst_helper.Payloadfor everything except its raising readers. The parser usesPStr []instead ofAst_payload.empty.ASTs from PPXes still get an error, from the compiler: for a field, the leftover
@asis read with the raising reader inBs_ast_invariantandRecord_runtime, as before. For a constructor, the leftover check now decodes the payload first, so it reports the invalid escape instead of the generic invalid-annotation error.Tests: a syntax test with invalid escapes on fields, constructors, a duplicate
@asand an inline record (tests/syntax_tests/data/parsing/errors/typeDef/asInvalidEscape.res), which crashes on master; unit tests thatAst_helper.Type.fieldandType.constructorkeep an@asthey cannot read, and that the compiler then reports the escape for both (Ast_untagged_variants.process_constructor_tag,Record_runtime.extra_as_attribute).🤖 Generated with Claude Code
https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH