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

Invalid codegen with default argument invalid in generic context #13270

Closed
refi64 opened this issue Jan 27, 2020 · 1 comment · Fixed by #24119
Closed

Invalid codegen with default argument invalid in generic context #13270

refi64 opened this issue Jan 27, 2020 · 1 comment · Fixed by #24119

Comments

@refi64
Copy link
Contributor

refi64 commented Jan 27, 2020

I couldn't really think of a better title (why do I always run into the weirdest bugs), so here's an example:

Example

type
  A = object
  B = object

proc f(a: A) = discard

proc g[T](value: T, cb: (proc(a: T)) = f) =
  cb value

# This should fail because there is no f(a: B) overload available
g B()

Current Output

/usercode/nimcache/@min.nim.c: In function 'NimMainModule':
/usercode/nimcache/@min.nim.c:138:34: error: expected expression before ')' token
  g__blFRD9cre3iSc5obJINpxvg(T1_, );
                                  ^
Error: execution of an external program failed: 'gcc -c  -w  -I/playground/nim/lib -I/usercode -o /usercode/nimcache/@min.nim.c.o /usercode/nimcache/@min.nim.c'

Expected Output

A compiler error because g(a: B) does not exist.

Possible Solution

I'm honestly not sure why this occurs, but it's definitely related to the default value of cb. If I remove the default and pass f as a second argument to g at the call site, an error is properly displayed.

$ nim -v
Nim Compiler Version 1.0.6
@ghost ghost added the Invalid Code Acceptance Everything related to compiler not complaining about invalid code label Jul 26, 2020
@metagn
Copy link
Collaborator

metagn commented Sep 5, 2024

Now gives

Error: type mismatch: got <proc (a: A){.noSideEffect, gcsafe.}> but expected 'proc (a: B){.closure.}'
  Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.

probably since #24006

@Araq Araq removed the Invalid Code Acceptance Everything related to compiler not complaining about invalid code label Sep 6, 2024
metagn added a commit to metagn/Nim that referenced this issue Sep 16, 2024
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