Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same attribute can be matched by multiple ppxes. #564

Open
jaymody opened this issue Feb 13, 2025 · 2 comments
Open

Same attribute can be matched by multiple ppxes. #564

jaymody opened this issue Feb 13, 2025 · 2 comments

Comments

@jaymody
Copy link
Contributor

jaymody commented Feb 13, 2025

The following:

let () =
  let make_rule name =
    Context_free.Rule.attr_str_type_decl_expect
      (Attribute.declare
         name
         Type_declaration
         Ast_pattern.(pstr nil)
         (fun x -> x))
      (fun ~ctxt:_ _ _ _ ->
        let loc = Location.none in
        [ Ast_builder.Default.(pstr_eval ~loc (estring ~loc ("I am " ^ name)) []) ])
  in
  Driver.register_transformation
    "foobar"
    ~rules:[ make_rule "bar.foo"; make_rule "qux.foo" ];

Would allow:

type t = int [@@bar.foo]
"I am bar.foo"
[@@@end]

type u = int [@@qux.foo]
"I am qux.foo"
[@@@end]

type v = int [@@foo]
"I am bar.foo";;
"I am qux.foo"
[@@@end]

It seems that ppxlib doesn't protect against an attribute from being matched by two (or more) different Attribute.t declarations in instances when the name is ambiguous. The same issue exists for Attribute.Floating.ts.

@NathanReb
Copy link
Collaborator

I wonder how much of a problem that actually is. Aside from the ambiguity to the user, it does not seem to be particularly harmful.

Do you have an example of a concrete issue this has lead to? Do you think fixing this a prerequisite to releasing #560 ?

I want to clarify that I'm not saying we should necessarily keep this behaviour, I'm simply trying to assess the implications.

@jaymody
Copy link
Contributor Author

jaymody commented Feb 18, 2025

The concrete issue here would be that some ppxes may decide to use their own [@@@myppx.end] attribute. In such cases, [@@@end] would get interpreted for both myppx and as deriving.end.

Users can always temporarily work around this by forcing their [@@@myppx.end] to be fully qualified, but thought I'd just file an issue to document this bug, if ever it becomes more relevant to fix in the future.

I don't think this is blocking for releasing #560.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants