Skip to content

Commit 0b64bf2

Browse files
cknittclaude
andcommitted
Keep fixed-argument payloads with attributes as written
`@as(@foo 1) _` stays an attribute, so `@foo` is not dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NP47qMfjMbjUTKZDsLthDo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 99b7a84 commit 0b64bf2

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎compiler/ml/ast_fixed_arg.ml‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ open Parsetree
22

33
let of_payload (payload : payload) : fixed_value Location.loc option =
44
match payload with
5-
| PStr [{pstr_desc = Pstr_eval ({pexp_desc; pexp_loc}, _); pstr_loc = loc}]
6-
-> (
5+
(* A payload with attributes stays an attribute, which keeps them. *)
6+
| PStr
7+
[
8+
{
9+
pstr_desc = Pstr_eval ({pexp_desc; pexp_loc; pexp_attributes = []}, []);
10+
pstr_loc = loc;
11+
};
12+
] -> (
713
let fixed txt = Some {Location.txt; loc} in
814
match pexp_desc with
915
| Pexp_constant (Pconst_integer (source, None)) ->
@@ -13,7 +19,8 @@ let of_payload (payload : payload) : fixed_value Location.loc option =
1319
fixed (Pfixed_template source)
1420
| Pexp_tagged_template
1521
{
16-
tag = {pexp_desc = Pexp_ident {txt = Lident "json"}};
22+
tag =
23+
{pexp_desc = Pexp_ident {txt = Lident "json"}; pexp_attributes = []};
1724
raw_sources = [source];
1825
values = [];
1926
} ->

‎tests/syntax_tests/data/printer/typexpr/expected/fixedExternal.res.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ external makeOptions: (
2626
external commented: (/* a */ /* b */ @as(1) _ /* c */, /* d */ @as("s") _, int) => int = "f"
2727

2828
type notExternal = (@as(1) _, int) => int
29+
30+
@val external payloadAttributes: (@as(@foo (1)) _, @as(@foo (json`{}`)) _, int) => int = "f"

‎tests/syntax_tests/data/printer/typexpr/fixedExternal.res‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ external useEffect0: (unit => option<unit => unit>, @as(json`[]`) _) => unit = "
2020
external commented: (/* a */ @as(1) /* b */ _ /* c */, @as(/* d */ "s") _, int) => int = "f"
2121

2222
type notExternal = (@as(1) _, int) => int
23+
24+
@val external payloadAttributes: (@as(@foo 1) _, @as(@foo json`{}`) _, int) => int = "f"

0 commit comments

Comments
 (0)