Semantic Diff

#9359 Fix parser crash on invalid @as escapes

1 commit

a82617064bae3aa9eb1b070b5fc85bb8abfcb422..pr-9359

ec3592fd8 · cknitt + Claude · Nov 20, 2026, 21:17 UTC

Fix parser crash on invalid @as escapes

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.

modifiedDiagnostic invalid @as escape

type t = {@as(`\xZZ`) x: int}
diagnostic
Before res_parser -recover
After res_parser -recover
Fatal error: exception Location.Error(_) Syntax error!t.res:1:16-19Invalid 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.