-
-
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
Inconsistent template behavior (bind vs. mixin) #3542
Comments
Workaround: b.nim template foobar*() =
mixin pop # force `pop` symbol to be open
pop() |
The compiler and the spec agree. In your first example 'foo' is unbound identifier because system doesn't have 'foo', so it is put into a 'mixin' context. In your second example 'pop' is not unbound, but it is not overloaded either, so it is put into a 'bind' context. The manual needs to be updated with an example like this, but apart from that it works as indented. |
I feel that this is problematic though, because module b.nim cannot possibly know all existing symbols in advance. So it either needs to always use mixin for its template usages (which is cumbersome), or it may inadvertently break in the future if c.nim suddenly decided to import some other module that conflicts. In other words: module b.nim can break by modifying unrelated module c.nim |
a.nim template blah*() = discard b.nim template foobar*() = blah() c.nim import a, b
foobar() d.nim proc blah*() = discard This will compile, but if we add |
Yup. It's really bad, but I know of no alternative solution that is as convenient in practice. And also in practice it hasn't come up. |
This is a different topic though, IMO. The compiler is right and then it becomes ambiguous. |
Well, it came up for me today while writing a library of reusable templates :) Can't the compiler know that both template foo and proc foo exist, and then pick the best match? |
But that is exactly what it does? |
No, it doesn't seem to find the mixin template if a symbol exists:
Should have found a.pop as well, no? |
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions. |
The following setup works:
a.nim
b.nim
c.nim
However, if we replace the template
a.foo
with an overload of an existing template, such assystem.pop
, the code no longer compiles, because the compiler only findssystem.pop
:a.nim
b.nim
c.nim
Output:
The text was updated successfully, but these errors were encountered: