.. type representation, attaching them to the type declaration instead of dropping them.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
@schematype t = @s.strict { email: string, name: string,}type u = @attr {x: {y: int}}
@schematype 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"
@schema @s.stricttype 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.
- No effect
- Output: unchangedFormats: nonePPX: unchangedEditor: unchanged
- Formatting
- changed
type t = @a {...}andtype t = @a ..now print as@a type t = ...instead of dropping@a - Tests
- syntax
tests/syntax_tests/data/~ parsing/grammar/typedefinition/typeRepresentation.res~ parsing/grammar/typedefinition/expected/typeRepresentation.res.txt~ parsing/grammar/typedefinition/expected/recordDeclaration.res.txt~ printer/typeDef/attributes.res~ printer/typeDef/expected/attributes.res.txt
- Changelog fragment changes/type-representation-attributes.fix.md
- No committed generated JS changes
7 files ยท +104 โ58 ยท changelog 1 ยท syntax 1 ยท tests 5
| A | changes/type-representation-attributes.fix.md | +1 | โ0 |
| M | compiler/syntax/src/res_core.ml | +63 | โ52 |
| M | tests/syntax_tests/data/parsing/grammar/typedefinition/expected/recordDeclaration.res.txt | +2 | โ2 |
| M | tests/syntax_tests/data/parsing/grammar/typedefinition/expected/typeRepresentation.res.txt | +15 | โ4 |
| M | tests/syntax_tests/data/parsing/grammar/typedefinition/typeRepresentation.res | +4 | โ0 |
| M | tests/syntax_tests/data/printer/typeDef/attributes.res | +9 | โ0 |
| M | tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt | +10 | โ0 |