You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bc9e90b
Browse filesBrowse the repository at this point in the historyBrowse files
Keep attributes in front of a record or open type representation
The parser accepts attributes and doc comments between `=` and a record
declaration or `..` (since #7787) but threw them away. They now go on the
type declaration, after its leading attributes, so PPXs and the type
checker see them; the formatter prints them in front of `type`. The
attributed path also passes the inline-record context on, so nested
record types inside such a record parse.
Example (rescript):
@Schema
type t = @s.strict {
email: string,
name: string,
}
type u = @attr {x: {y: int}}
Before (rescript):
@Schema
type t = {
email: string,
name: string,
}
// type u: "An inline record type declaration is only allowed in a
// variant constructor's declaration or nested inside of a record type
// declaration"
After (rescript):
@Schema@s.strict
type t = {
email: string,
name: string,
}
@attr type u = {x: {y: int}}
Review: Why the declaration and not an error? The issue asks for the
attribute to reach the PPX, and the declaration is the only parsetree node
a record or open type kind has. An attribute in front of a constructor
still attaches to that constructor.
Area: syntax tests
Output: unchanged
Formatting: changed `type t = @A {...}` and `type t = @A ..` now print as
`@a type t = ...` instead of dropping `@a`
Formats: none
PPX: unchanged
Editor: unchanged
Tests: ~tests/syntax_tests/data/parsing/grammar/typedefinition/typeRepresentation.res
~tests/syntax_tests/data/parsing/grammar/typedefinition/expected/typeRepresentation.res.txt
~tests/syntax_tests/data/parsing/grammar/typedefinition/expected/recordDeclaration.res.txt
~tests/syntax_tests/data/printer/typeDef/attributes.res
~tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
- Keep attributes and doc comments written in front of a record or `..` type representation, attaching them to the type declaration instead of dropping them.
0 commit comments