-
-
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
fix dot calls with resolved symbols in templates #22076
Changes from 5 commits
e3a5f22
d8d7ba2
4f2d718
f68e869
865c7a5
7f46843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,17 +134,14 @@ template main = | |
|
||
block: # bug 1 from https://github.com/nim-lang/Nim/pull/17020#issuecomment-803193947 | ||
macro deb1(a): untyped = newLit a.repr | ||
macro deb2(a): untyped = newLit a.lispRepr | ||
macro deb2(a): untyped = | ||
a[1] = ident($a[1]) | ||
newLit a.lispRepr | ||
doAssert deb1(-12'wrap) == "-12'wrap" | ||
doAssert deb1(-12'nonexistent) == "-12'nonexistent" | ||
doAssert deb2(-12'nonexistent) == """(DotExpr (RStrLit "-12") (Ident "\'nonexistent"))""" | ||
when false: # xxx bug: | ||
# this holds: | ||
doAssert deb2(-12.wrap2) == """(DotExpr (IntLit -12) (Sym "wrap2"))""" | ||
doAssert deb2(-12'wrap) == """(DotExpr (RStrLit "-12") (Sym "\'wrap"))""" | ||
# but instead this should hold: | ||
doAssert deb2(-12.wrap2) == """(DotExpr (IntLit -12) (Ident "wrap2"))""" | ||
doAssert deb2(-12'wrap) == """(DotExpr (RStrLit "-12") (Ident "\'wrap"))""" | ||
doAssert deb2(-12.wrap2) == """(DotExpr (IntLit -12) (Ident "wrap2"))""" | ||
doAssert deb2(-12'wrap) == """(DotExpr (RStrLit "-12") (Ident "\'wrap"))""" | ||
|
||
block: # bug 2 from https://github.com/nim-lang/Nim/pull/17020#issuecomment-803193947 | ||
template toSuf(`'suf`): untyped = | ||
|
@@ -165,21 +162,16 @@ template main = | |
doAssert fn2() == "[[-12]]" | ||
doAssert fn3() == "[[-12]]" | ||
|
||
when false: # xxx this fails; bug 9 from https://github.com/nim-lang/Nim/pull/17020#issuecomment-803193947 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meanwhile this was actually the bug fixed by this PR, custom numeric literals generate dot fields which did not keep their resolved symbols in templates. It really wouldn't have taken much investigation to figure out this is related to dot fields and has nothing to do with custom numeric literals. The linked comment thinks it has something to do with |
||
#[ | ||
possible workaround: use `genAst` (https://github.com/nim-lang/Nim/pull/17426) and this: | ||
let a3 = `'wrap3`("-128") | ||
]# | ||
block: | ||
macro metawrap(): untyped = | ||
func wrap1(a: string): string = "{" & a & "}" | ||
func `'wrap3`(a: string): string = "{" & a & "}" | ||
result = quote do: | ||
let a1 = wrap1"-128" | ||
let a2 = -128'wrap3 | ||
metawrap() | ||
doAssert a1 == "{-128}" | ||
doAssert a2 == "{-128}" | ||
block: # bug 9 from https://github.com/nim-lang/Nim/pull/17020#issuecomment-803193947 | ||
macro metawrap(): untyped = | ||
func wrap1(a: string): string = "{" & a & "}" | ||
func `'wrap3`(a: string): string = "{" & a & "}" | ||
result = quote do: | ||
let a1 {.inject.} = wrap1"-128" | ||
let a2 {.inject.} = -128'wrap3 | ||
metawrap() | ||
doAssert a1 == "{-128}" | ||
doAssert a2 == "{-128}" | ||
|
||
static: main() | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type Foo = object | ||
proc foo(f: Foo) = discard | ||
|
||
template works*() = | ||
var f: Foo | ||
foo(f) | ||
|
||
template boom*() = | ||
var f: Foo | ||
f.foo() # Error: attempting to call undeclared routine: 'foo' | ||
f.foo # Error: undeclared field: 'foo' for type a.Foo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# issue #20073 | ||
|
||
import mdotcall | ||
|
||
works() | ||
boom() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not a bug. It's because this code is in a giant
main
template, which binds the outer'wrap
andwrap2
, because that's how the language works.