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

give type macro pragmas unary type section with experimental switch #24245

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Oct 5, 2024

closes #13830, fixes #15334, fixes #18864

With the experimental switch --experimental:typedTypeMacroPragma (shortest name I could think of), macro pragmas in type definitions now receive a unary nnkTypeSection node as input rather than nnkTypeDef. This means these macros can receive typed arguments, since a standalone nnkTypeDef as a statement is rejected by the compiler.

This is experimental because macros may not expect nnkTypeSection as input, only expecting nnkTypeDef and operating on it. However it is possible to be compatible with either input, see what I do in skinsuit. Unfortunately it's not as easy to tell if a macro is called as a pragma in a type section now, but this problem also exists with proc/var macro pragmas and a workaround exists which is to check if the macro did not originally receive nnkStmtList. Worst case we can come up with a more general solution.

We don't have to merge this immediately, I just figured it was overdue for such an old issue and made a PR as soon as I could.

@metagn
Copy link
Collaborator Author

metagn commented Oct 5, 2024

Surprisingly no packages failed with the switch enabled globally, probably none use type macro pragmas, but it's still easy to write macros that are compatible with either option.

@metagn metagn marked this pull request as ready for review October 5, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant