give type macro pragmas unary type section with experimental switch #24245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 unarynnkTypeSection
node as input rather thannnkTypeDef
. This means these macros can receivetyped
arguments, since a standalonennkTypeDef
as a statement is rejected by the compiler.This is experimental because macros may not expect
nnkTypeSection
as input, only expectingnnkTypeDef
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 receivennkStmtList
. 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.