-
-
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 #13443 Underscore cannot be defined more than once in proc #17581
Conversation
It doesn't work with templates. template main() =
var x = 0
proc foo(_, _: int) = x += 5
foo(1, 2)
doAssert x == 5 |
yes i think that snippet should compile. can be done in subsequent PR though |
compiler/semtypes.nim
Outdated
@@ -40,12 +40,6 @@ const | |||
errNoGenericParamsAllowedForX = "no generic parameters allowed for $1" | |||
errInOutFlagNotExtern = "the '$1' modifier can be used only with imported types" | |||
|
|||
|
|||
proc isDiscardUnderscoreV(v: PSym): bool = |
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.
i still don't like the duplication, instead just rename this to:
proc handleUnderscore(v: PSym): bool = ...
@@ -54,6 +54,9 @@ proc mangleParamName(m: BModule; s: PSym): Rope = | |||
## we cannot use 'sigConflicts' here since we have a BModule, not a BProc. | |||
## Fortunately C's scoping rules are sane enough so that that doesn't | |||
## cause any trouble. | |||
if s.name.s == "_": |
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.
can there be something similar for js? or what prevents this?
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.
It just didn't work for JS VM I guess a known bug
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.
tunderscore.nim(9, 27) Error: cannot evaluate at compile time: x
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.
in this case we should leave #13443 open (with a note) until we can address this :)
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.
why, that's the bug of js vm, not related to my PR?
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.
fine, I'll just open a new bug for js+vm then
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 shouldn't be handled in the backend IMO.
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.
maybe, what do you suggest concretely?
(see also the items i added in future work)
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.
Can't we just mangle if sfGensym in s.flags
?
if s.name.s == "_": | |
if sfGensym in s.flags: |
block: | ||
proc ok(_, _, a: int): int = a | ||
doassert ok(4, 2, 5) == 5 | ||
|
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.
block: | |
iterator fn(_, _: int, c: int): int = yield c | |
doAssert toSeq(fn(1,2,3)) == @[3] |
and add from std/sequtils import toSeq on top
This PR is needed to fix #13804 (which the checkboxes in the main post describe). There would only be a small patch in semtempl, namely putting these lines inside Lines 645 to 646 in 779b1cc
If we don't want the backend mangling parameter names, we can whitelist the changes in As for the |
fix #13443
future work
ditto with procs:
before PR: works
after PR: Error: undeclared identifier: '_'
__attribute__((unused))
in cgen for the corresponding parameters