-
-
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
quote do generates wrong type for set[char] #11986
Comments
Bad example above, this shows it better:
Results in:
|
You forgot to use newLit. import macros
macro foo(): untyped =
var s = newLit({ 'a', 'b' })
quote do:
let t = `s`
echo typeof(t)
foo() The new |
Quoting Arne Döring (2019-08-20 20:36:44)
You forgot to use newLit.
Aaarg, *again*! Can't we make this mandatory somehow?
…--
:wq
^X^Cy^K^X^C^C^C^C
|
Yes. That is one of the requirements of the new quoteAst |
I added a test for both of your examples in #11722, which is another proposal to replace unlike #11823, you don't need to add an intermediate variable quote do: some code with `foo` by genAst(foo): some code with foo block: # fix https://github.com/nim-lang/Nim/issues/11986
proc foo(): auto =
var s = { 'a', 'b' }
var n = genAst(s): s
n.repr
static: doAssert foo() == "{'a', 'b'}"
block: # also from #11986
macro foo(): untyped =
var s = { 'a', 'b' }
genAst(s):
let t = s
$typeof(t)
doAssert foo() == "set[char]" |
* new `macros.genAst`: fixes all issues with `quote do` * add changelog entry * add workaround for #2465 (comment) * add test for #9607 * add kNoExposeLocalInjects option * add test case for nested application of genAst * genAst: automatically call newLit when needed * allow skipping `{}`: genAst: foo * add test that shows this fixes #11986 * add examples showing mixin; add examples showing passing types, macros, templates * move to std/genasts * improve docs
…nim-lang#9607; rework quote do; `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (nim-lang#21433) * fixes nim-lang#21326; getAst uses type info to annotateType quoted variables * simplify logics; sem types first * fixes important packages * add testcases * tiny
…nim-lang#9607; rework quote do; `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (nim-lang#21433) * fixes nim-lang#21326; getAst uses type info to annotateType quoted variables * simplify logics; sem types first * fixes important packages * add testcases * tiny
I'm having problems passing
set[char]
throughquote do
blocks. The generated literal loses its charness, resulting in aset[uint16]
instead.The following snippet prints
{97, 98}
instead of{'a', 'b'}
:The text was updated successfully, but these errors were encountered: