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

Make "required type for cb: Callback" error point me toward fixing the problem #13539

Closed
iffy opened this issue Feb 29, 2020 · 1 comment
Closed

Comments

@iffy
Copy link
Contributor

iffy commented Feb 29, 2020

Summary

Compiling this program produces the following error:

import asyncdispatch
let event = newAsyncEvent()
event.addEvent(proc() =
  echo "Event signalled"
)
event.trigger()
event.trigger()

Compiler error:

$ nim c --hints:off /tmp/events.nim 
/private/tmp/events.nim(4, 6) Error: type mismatch: got <AsyncEvent, proc (){.gcsafe, locks: 0.}>
but expected one of: 
proc addEvent(ev: AsyncEvent; cb: Callback)
  first type mismatch at position: 2
  required type for cb: Callback
  but expression 'proc () = echo ["Event signalled"]' is of type: proc (){.gcsafe, locks: 0.}

expression: addEvent(event, proc () = echo ["Event signalled"])

As an inexperienced Nim user, though, I don't know in what way my proc doesn't meet the requirements to be a Callback.

It would be nice if the definition of Callback was included in the error output. Or it would be nice if the documentation for addEvent included a link to the definition of Callback

I should have tried on a newer Nim version, but it's bedtime:

$ nim --version
Nim Compiler Version 1.0.2 [MacOSX: amd64]
Compiled at 2019-10-22
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 193b3c66bbeffafaebff166d24b9866f1eaaac0e
active boot switches: -d:release
alaviss added a commit to alaviss/Nim that referenced this issue Apr 21, 2020
This let us see the definition of `Callback` in docs, which is required
to even make use of asyncdispatch.

Ref nim-lang#13539.
Araq pushed a commit that referenced this issue Apr 21, 2020
This let us see the definition of `Callback` in docs, which is required
to even make use of asyncdispatch.

Ref #13539.
narimiran pushed a commit that referenced this issue Apr 23, 2020
This let us see the definition of `Callback` in docs, which is required
to even make use of asyncdispatch.

Ref #13539.

(cherry picked from commit 7beed44)
narimiran pushed a commit that referenced this issue Apr 23, 2020
This let us see the definition of `Callback` in docs, which is required
to even make use of asyncdispatch.

Ref #13539.

(cherry picked from commit 7beed44)
@metagn
Copy link
Collaborator

metagn commented Jun 23, 2024

Error message is now:

Error: type mismatch
Expression: addEvent(event, proc () = echo ["Event signalled"])
  [1] event: AsyncEvent
  [2] proc () = echo ["Event signalled"]: proc (){.gcsafe.}

Expected one of (first mismatch at [position]):
[2] proc addEvent(ev: AsyncEvent; cb: Callback)
  expression 'proc () = echo ["Event signalled"]' is of type: proc (){.gcsafe.}
  Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.

The reason is shown at the bottom, the calling convention is different.

@metagn metagn closed this as completed Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants