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

Tuple type mismatch with proc() - Returns None #13849

Closed
PixeyeHQ opened this issue Apr 2, 2020 · 4 comments · Fixed by #20932
Closed

Tuple type mismatch with proc() - Returns None #13849

PixeyeHQ opened this issue Apr 2, 2020 · 4 comments · Fixed by #20932

Comments

@PixeyeHQ
Copy link

PixeyeHQ commented Apr 2, 2020

For some reason sending a proc() to a tuple returns None with specific proc names. By far I get None when naming procs as close() , dispose(), finished()

type mismatch: got <int, tuple of (proc (){.noSideEffect, gcsafe, locks: 0.}, None)>

Example

proc start*()=discard
proc tick*(delta:float)=discard
proc close*()=discard

# just to show the tuple
proc set_scn_ev*(id:int, events: tuple[start: proc(){.nimcall.}, close: proc(){.nimcall.}])=
  discard
# proc check
proc set_scn_ev*(id:int, ev: proc(){.nimcall.})=
  discard

set_scn_ev(id_scene_game,(start,close)) # error, close is treated as None
set_scn_ev(id_scene_game,close) # but this Is OK

Current Output

type mismatch: got <int, tuple of (proc (){.noSideEffect, gcsafe, locks: 0.}, None)>

Expected Output

It should compile

Nim Compiler Version 1.0.6 [Windows: amd64]
Nim Compiler Version 1.2.0 [Windows: amd64]
@metagn
Copy link
Collaborator

metagn commented Apr 3, 2020

Expected behaviour. close can mean either your proc or this proc for closing files. What you have to do is qualify it, like yourmodulename.close. finished and dispose are also defined in system.

@PixeyeHQ
Copy link
Author

PixeyeHQ commented Apr 3, 2020

Thanks for your answer :)

👍 I agree that those can be defined in System but let's look at this problem from a different angle.
I'm a developer that wants to get a result and do things that from my point of view are legal. And as nothing prevents me from writing that code - I can write that code
And I get EXTREMELY confused because

  1. I still can define my custom finished proc to the proc() variable, it doesn't give me any error but gives me when I use that in a tuple.

  2. The error itself gives me very little understanding of what's happening.
    but expression '(start, finished)' is of type: tuple of (proc (){.noSideEffect, gcsafe, locks: 0.}, None)

Why it's None? I guess it could be much more informative if the error would be

Hey, you are trying to redefine the proc name finished from the system module, if you still wish to do what you want to consider adding [YOUR_MODULE_NAME].

What do you think about that?

@PixeyeHQ PixeyeHQ changed the title [Bug] Tuple type mismatch with proc() - Returns None Tuple type mismatch with proc() - Returns None Apr 3, 2020
@ghost
Copy link

ghost commented Apr 3, 2020

Well, 1 is because Nim supports procedure overloading, so you can call both close as in your procedure, or close from system module by specifying different number of arguments (without the need to specify which module to call it from)

Although I agree that error message is really confusing

@metagn
Copy link
Collaborator

metagn commented Apr 3, 2020

Sorry, I was going to talk about the error message but I forgot, this isn't the first "type None" procvar error message issue, namely #6359 I would say is the same issue. I wouldn't close this for a duplicate though since #6359 doesn't really have a lot of examples but these issues are related and fixing both should be the focus.

metagn added a commit to metagn/Nim that referenced this issue Nov 26, 2022
Araq pushed a commit that referenced this issue Dec 1, 2022
* better procvar ambiguity errors, clean up after #20457

fixes #6359, fixes #13849

* only trigger on closedsymchoice again

* new approach

* add manual entry for ambiguous enums too

* add indent [skip ci]

* move to proc
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
…ang#20932)

* better procvar ambiguity errors, clean up after nim-lang#20457

fixes nim-lang#6359, fixes nim-lang#13849

* only trigger on closedsymchoice again

* new approach

* add manual entry for ambiguous enums too

* add indent [skip ci]

* move to proc
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…ang#20932)

* better procvar ambiguity errors, clean up after nim-lang#20457

fixes nim-lang#6359, fixes nim-lang#13849

* only trigger on closedsymchoice again

* new approach

* add manual entry for ambiguous enums too

* add indent [skip ci]

* move to proc
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…ang#20932)

* better procvar ambiguity errors, clean up after nim-lang#20457

fixes nim-lang#6359, fixes nim-lang#13849

* only trigger on closedsymchoice again

* new approach

* add manual entry for ambiguous enums too

* add indent [skip ci]

* move to proc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants