diff --git a/CHANGES.md b/CHANGES.md index b325ed3b6..fd74077bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 ------ diff --git a/src/extension.ml b/src/extension.ml index 9f4fe17c8..782b1f1e3 100644 --- a/src/extension.ml +++ b/src/extension.ml @@ -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 diff --git a/test/driver/attributes/test.ml b/test/driver/attributes/test.ml index a21605e29..de386fea7 100644 --- a/test/driver/attributes/test.ml +++ b/test/driver/attributes/test.ml @@ -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 +|}]