Skip to content

Commit 18c0c1c

Browse files
Merge pull request #613 from patricoferris/fix-attr-error-loop
Fix attr error loop
2 parents 7a89a69 + 8ef30ac commit 18c0c1c

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
unreleased
22
----------
33

4+
- Fix infinite loop when duplicate attributes are present, raising
5+
an error instead (#613, @ceastlund, @patricoferris)
6+
47
0.37.0
58
------
69

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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,33 @@ Test that the "attr_multiple_replace" infrastructure works.
123123
> EOF
124124
$ ./driver.exe test.ml
125125
let _ = ((prefix_foo_suffix)[@alert "-1"][@alert "-2"][@alert "-3"])
126+
127+
Demonstrate error when multiple instances of one attribute are passed.
128+
$ cat > test.ml << EOF
129+
> let _ =
130+
> foo
131+
> [@prefix "prefix_"]
132+
> [@suffix "_suffix"]
133+
> [@suffix "_again"]
134+
> EOF
135+
$ ./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)