-
-
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
[Macro] cannot pass a distinct type to newLit #13266
Labels
Comments
Here is how you do it. You need latest devel nim, because of import macros
type
Rune = distinct int32
Foo = object
a: Rune
proc `$`(r: Rune): string {.borrow.}
import typetraits
proc newLit*(d: distinct): NimNode =
nnkCall.newTree(typeof(d).getTypeInst,
newLit(distinctBase(typeof(d))(d)))
macro foo*(): untyped =
result = newStmtList()
let runeLit = newLit Rune(0)
let fooLit = newLit Foo(a: Rune(0))
result.add(quote do:
echo `runeLit`)
result.add(quote do:
echo `fooLit`.a)
proc main() =
foo()
main() |
Wouldn't it be better to have this overload of |
@andreaferretti I did exactly that in my PR (linked above). |
ghost
added
the
Macros
label
Jul 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cannot pass a distinct type to newLit. Using the values directly seems to work in my case, but the docs/tutorial say to convert them to NimNode using newLit.
Example
Current Output
Expected Output
The text was updated successfully, but these errors were encountered: