Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unreleased

- Fix infinite loop when duplicate attributes are present, raising
an error instead (#613, @ceastlund, @patricoferris)
- Ignore extensions inside attributes for the unused extension check
(#616, @Skepfyr)

0.37.0
------
Expand Down
4 changes: 4 additions & 0 deletions src/extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ let collect_unhandled_extension_errors =
"extension not expected here, Ppxlib.Extension needs updating!";
]

(* Skip extensions in attributes, they will be handled by the PPX that
handles each specific attribute. *)
method! attribute _x acc = acc

method! core_type_desc x acc =
match x with
| Ptyp_extension ext -> acc @ unhandled_extension_error Core_type ext
Expand Down
25 changes: 25 additions & 0 deletions test/driver/attributes/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,28 @@ let e = [%flag_ghost "bye" [@flag]]
[%%expect{|
val e : string * string = ("bye", "bye")
|}]

(* Test extensions aren't flagged as unused inside attributes. *)

let () =
let attr =
Attribute.declare
"ignore_me"
Attribute.Context.core_type
Ast_pattern.(__)
ignore
in
let ext =
Extension.V3.declare
"ignore_me"
Core_type
Ast_pattern.(ptyp __)
(fun ~ctxt:_ e -> let (_ : unit option) = Attribute.get attr e in e)
in
Driver.register_transformation "ignore_me" ~rules:[ Context_free.Rule.extension ext ]
;;

type t = [%ignore_me: int[@ignore_me [%doesn't_exist]]]
[%%expect{|
type t = int
|}]