Skip to content

Commit 463ec5b

Browse files
committed
Raise errors early when there are duplicated attributes
Signed-off-by: Patrick Ferris <[email protected]>
1 parent 332b9c3 commit 463ec5b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/context_free.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ let handle_attr_replace_once context attrs item base_ctxt : 'a option t =
366366
| [] -> return (false, Rule.Attr_replace.Parsed_payload_list.[])
367367
| x :: xs ->
368368
(if Attribute.Context.equal context (Attribute.context x) then
369-
Attribute.get_res x item |> of_result ~default:None
369+
return @@ Attribute.get x item
370370
else return None)
371371
>>= fun p ->
372372
get_attr_payloads xs >>| fun (any_attrs, ps) ->
@@ -377,10 +377,10 @@ let handle_attr_replace_once context attrs item base_ctxt : 'a option t =
377377
if any_attrs then
378378
Some
379379
( (payloads, errors) >>= fun payloads ->
380-
Attribute.remove_seen_res context
381-
(Rule.Attr_replace.Attribute_list.to_packed_list a.attributes)
382-
item
383-
|> of_result ~default:item
380+
return
381+
@@ Attribute.remove_seen context
382+
(Rule.Attr_replace.Attribute_list.to_packed_list a.attributes)
383+
item
384384
>>| fun item -> a.expand ~ctxt:base_ctxt item payloads )
385385
else None)
386386
in

test/attr_replace/run.t

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,23 @@ Demonstrate error when multiple instances of one attribute are passed.
133133
> [@suffix "_again"]
134134
> EOF
135135
$ ./driver.exe test.ml
136+
File "test.ml", line 5, characters 4-10:
137+
5 | [@suffix "_again"]
138+
^^^^^^
139+
Error: Duplicated attribute
140+
[1]
141+
142+
Demonstrate error when multiple instances of one attribute are passed and
143+
no other attributes are available.
144+
$ cat > test.ml << EOF
145+
> let _ =
146+
> foo
147+
> [@suffix "_suffix"]
148+
> [@suffix "_again"]
149+
> EOF
150+
$ ./driver.exe test.ml
151+
File "test.ml", line 4, characters 4-10:
152+
4 | [@suffix "_again"]
153+
^^^^^^
154+
Error: Duplicated attribute
155+
[1]

0 commit comments

Comments
 (0)