-
-
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
Calling nullary templates without () doesn't work inside calls inside other templates #13515
Comments
I think https://forum.nim-lang.org/t/5992 offers the key explanation:
so I think the title should be re-worded to reflect that
sorry can you elaborate? proposal (EDIT: timotheecour#183)
template test: bool {.implicitCall.} = true
doAssert test == true
doAssert not compiles(test())
template test2: bool = true
doAssert test2() == true
test2 == true # this should not compile
|
I wouldn't say that's a key explanation, more of a non sequitur. The case in #13209 (overloaded templates) is mentioned, which is unrelated to this. You can add a low priority tag if you deem it fit even though this issue doesn't seem to be that hard of a problem.
Sorry, that PR doesn't have anything to do with this, it's just that it uses the affected feature of this bug, meaning codebases that use it will have to deal with this. It doesn't block the PR, my mistake. |
i think a title like I still think that quote is 100% related; the issue you've opened is valid, the code should compile (because
you're absolutely right :) so we need to fix this... |
also note the {.dirty.} workaround, but obviously it's just a workaround and changes semantics #14332 (comment) |
This is a rather blatant and basic bug, and has nothing to do with overloading or This innocuous code doesn't work: template t1: int = 0
template t2 = echo t1
t2 Whereas this does: template t1: int = 0
echo t1 This is alpha quality stuff and makes the language look bad. Of course, the compiler is free and no one owes me anything, so having made that statement I should go fix this. It will be a while, as I have no familiarity with the compiler code. |
Most bugs seem blatant and basic until you delve into it and submit a fix. nim has more features than your average language and yes, they interact badly sometimes.
or maybe it's the other way around? implicit calls, just like implicit conversions (converter, ptr char=>cstring #13790, implicit deref, procvar => pointer (nim-lang/RFCs#229)) all sound good ideas at first until you realize they complicate the type system. eg related to this implicit call, you can't reliably do:
yes, PR's welcome. |
This is obviously not true. And in this case, what's blatant and basic has nothing to do with how hard it is to fix it; I'm talking about fundamental features of the language. If say, 1+1 produced 93, and it turned out to be due to some deep and complicated problem in the compiler that took months to fix, it would still be blatant and basic.
Features interacting badly means poor design. I don't think that's the case here ... it's just a bug. And yes, more features makes it harder to code the compiler correctly, but that's the cost one takes on when they design a feature-rich language. Templates are a great feature, but only if they work, and currently they are quite buggy. I encounter these bugs frequently ... I've submitted two, noticed dups of some others, and have a backlog of yet more that I need to investigate. As for "implicit calls", there's no such thing here; no implicit anything, and no "call". Templates are always expanded; unlike with procs, there is zero semantic difference between
P.S. It's not only nullary templates ... the problem is with the parenthesis-free invocation, not with the definition. Templates with optional parameters have the same issue. |
That's not a workaround for this ... |
Funnily enough method call syntax works. template test: bool = true
template x =
if test.not:
echo "wtf"
x |
* fix nim-lang#13515 * only compile test * no idea why this PR is unlocking this * don't rope in symchoices * even more restrictive
Example
Current Output
Expected Output
compiles
Workaround
Additional Information
not
isn't specifically needed here, any call/operator errors.if test:
compiles.The text was updated successfully, but these errors were encountered: