Skip to content
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

Underscore cannot be defined more than once in proc #13443

Closed
Wh1teDuke opened this issue Feb 20, 2020 · 6 comments · Fixed by #21192
Closed

Underscore cannot be defined more than once in proc #13443

Wh1teDuke opened this issue Feb 20, 2020 · 6 comments · Fixed by #21192

Comments

@Wh1teDuke
Copy link
Contributor

Test

proc foo(_, _: int) = discard

Expected
Compiles with no issue. It works for one underscore, though I'm not sure this is even a feature.

Got

Test.nim(1, 13) Error: attempt to redefine: '_'

>nim -v
Nim Compiler Version 1.1.1 [Linux: i386]
Compiled at 2020-02-19
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 8c22518d673cf792fa064d2d561d1c6f03b823bb
active boot switches: -d:release
@ringabout
Copy link
Member

Maybe this works as expected?

error: redefinition of parameter '_'
 N_LIB_PRIVATE N_NIMCALL(void, foo__BOpZ9bkFh9cyFk2iF9aui4mXw)(NI _, NI windx, NI _);

If the _ isn't mangled, it is natural to cause this result.

Maybe this needs to be documented instead of being fixed?

@timotheecour
Copy link
Member

timotheecour commented Nov 16, 2020

for consistency with (EDIT) #15972, IMO proc foo(_, _: int) = discard should be allowed.
Would avoid having to use dummy names eg in:
proc bar(a: int, fun: proc(_: int, _: float)) = discard

@ringabout
Copy link
Member

ringabout commented Nov 17, 2020

@timotheecour
Wrong RFC link.

If mangling underscore names is more consistent, I will try that.

@timotheecour
Copy link
Member

@xflywind thx, fixed link

ringabout added a commit to ringabout/Nim that referenced this issue Nov 17, 2020
@ringabout
Copy link
Member

ringabout commented Nov 17, 2020

Because JS backend mangles function parameters, it does work in JS backend and VM.

proc foo(_, _: int) = echo "123"

foo(1, 2)
function foo_385875969(__385875971, __385875972) {
  rawEcho(makeNimstrLit("123"));
}
foo_385875969(1, 2);

ringabout added a commit to ringabout/Nim that referenced this issue Nov 17, 2020
@timotheecour
Copy link
Member

timotheecour commented Mar 30, 2021

this should probably be legal:

proc foo(_, _: int) = discard

this should not be legal:

proc main(_: int) = echo _

see also nim-lang/RFCs#292 which defines a useful use case for passing _; that use case should be reserved

@ringabout ringabout self-assigned this Mar 30, 2021
ringabout added a commit to ringabout/Nim that referenced this issue Mar 30, 2021
@ringabout ringabout removed their assignment Sep 22, 2021
metagn added a commit to metagn/Nim that referenced this issue Dec 28, 2022
Araq pushed a commit that referenced this issue Jan 8, 2023
* underscores for routine parameters

fixes #13443, fixes #13804, refs #21121

* add changelog + more tests

* support generics and ensure inferred lambdas work
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
* underscores for routine parameters

fixes nim-lang#13443, fixes nim-lang#13804, refs nim-lang#21121

* add changelog + more tests

* support generics and ensure inferred lambdas work
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* underscores for routine parameters

fixes nim-lang#13443, fixes nim-lang#13804, refs nim-lang#21121

* add changelog + more tests

* support generics and ensure inferred lambdas work
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
* underscores for routine parameters

fixes nim-lang#13443, fixes nim-lang#13804, refs nim-lang#21121

* add changelog + more tests

* support generics and ensure inferred lambdas work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants