-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Typed type section macro doesn't work #18864
Comments
should it work? the type section can't be typed until it exists, i.e. has been processed through the macro. if type does it need to work? one has access to the full type declaration, what other information could you get? Edit: I'm convinced. Yes and yes. Bringing them up to parity with proc macros would be a nice feature. |
Yes it should work.
Why can't it be? There is nothing stopping the compiler from performing semantic checking and resolving symbols, as well as running any macros prior to the current one. This is how typed macros already work for
There shouldn't be a redefinition error. Think of types created in a typed macro context as created in a "shadow" scope, which is like an overlay on top of the current scope, and only after the macro have been run would the resulting AST be introduced to the real scope, which should eliminate all redefinition concerns. Again, typed macros for
I need the type symbols as resolved by the compiler, as well as other untyped/typed macros to have been resolved. |
The problem is really obvious (compiler tries to type We could always just pass a type section (as in #13830) but this would break every macro that only accepts an We could form a type section from the single typedef first, type it, then extract the single typedef from that and pass that to the macro, but this sounds hacky. For now we have this ugly workaround (although I like the import std/macros
macro testImpl(n: typed): untyped =
result = n
macro test(n: untyped): untyped =
result = newTree(nnkTypeDef, ident"_", newEmptyNode(), newStmtList(
newCall(bindSym"testImpl", newTree(nnkTypeSection, n)),
ident"void"))
echo result.treeRepr
type
X {.test.} = object Edit: Same issue: #15334 |
Example
Current Output
Additional Information
The text was updated successfully, but these errors were encountered: