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

Add show @printer support for polymorphic variants #286

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sim642
Copy link
Contributor

@sim642 sim642 commented Jun 1, 2024

This missing support is listed as one of the motivations for ppx_deriving_variant_string:

printer is only supported in polyvars for some reason, but not on regular variants, which was a feature we wanted to have

I quickly implemented this and only then discovered that #267 already exists.
The difference is that this is for the migrated ppxlib attributes and does use wrap_printer.

Copy link
Contributor

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is a nice thing to have, and the implementation in this PR is slightly better than #267. Let's not make it wait as long...

Could you maybe include a CHANGELOG entry to credit both you and @ghuysmans, so that we don't forget to do so later?

@@ -23,6 +23,7 @@ let attr_printer context = Attribute.declare "deriving.show.printer" context
Ast_pattern.(single_expr_payload __) (fun e -> e)
let ct_attr_printer = attr_printer Attribute.Context.core_type
let constr_attr_printer = attr_printer Attribute.Context.constructor_declaration
let rtag_attr_printer = attr_printer Attribute.Context.rtag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was lost for a while as to what rtag means. The answer is that this obscure name comes from the parsetree, and it means "a constructor declaration in a polymorphic variant type" (r means row and tag is supposed to suggest constructor, I guess). The other PR #267 uses attr_printer field.prf_attributes directly, and I suppose that usig the ppxlib mechanism as in here is better.

sim642 added a commit to sim642/ppx_deriving that referenced this pull request Jun 2, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
@sim642 sim642 force-pushed the show-poly-variant-printer branch from 34a5bff to fc7e50d Compare June 3, 2024 15:14
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

Successfully merging this pull request may close these issues.

2 participants