Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
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.
I couldn't really think of a better title (why do I always run into the weirdest bugs), so here's an example:
Example
Current Output
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 passf
as a second argument tog
at the call site, an error is properly displayed.