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

cryptic error message: ambiguous call: both strappend.strJoin and fun2.strJoin match, given strappend.strJoin() #8926

Open
timotheecour opened this issue Sep 9, 2018 · 0 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Sep 9, 2018

I got this cryptic error message, where it would seem there was no ambiguity given that I specified fully qualified name strappend.strJoin:

main.nim(9, 18) Error: ambiguous call; both strappend.strJoin(args: varargs[typed])[declared in strappend.nim(1, 6)] and fun2.strJoin(args: varargs[typed])[declared in fun2.nim(1, 6)] match for: (proc (s: var string, args: varargs[typed]): untyped{.noSideEffect, gcsafe, locks: 0.})
  discard strappend.strJoin()
                   ^

Here's the full code to reproduce (after I reduced it)

# main.nim

when defined(case_ok):
  import ./strappend

import ./all
import ./fun2
discard strappend.strJoin()
#all.nim
import ./strappend
import ./fun1

export strappend, fun1
#strappend.nim
macro strJoin*(args: varargs[typed]): untyped = discard
proc foobar*()=discard
# fun1.nim
macro strAppend*(s: var string, args: varargs[typed]): untyped = discard
#fun2.nim
macro strJoin*(args: varargs[typed]): untyped = discard

The root cause is that strappend.strJoin() is interpreted as strJoin(strAppend) using strAppend from fun1.nim, but that was really not obvious in my original scenario, especially given that fun1 was not directly imported by main.nim (only indirectly, via a re-export in all.nim), and import ./strappend was hidden by hidden by conditional compilation

proposal

  • P1: show: expression: strJoin(strAppend) in the ambiguous call error message, as is done for type mismatch error, eg:
Error: type mismatch: got <proc (x: varargs[typed]){.gcsafe, locks: 0.}>
but expected one of:
macro strAppend(s: var string; args: varargs[typed]): untyped

expression: strappend(echo)
  echo .strappend.strJoin("asfd")
       ^
  • P2 (in addition to P1): more controversial, but IMO would solve a number of problems, including UFCS with fully qualified name, as well as removing ambiguities like in this issue:
    allow using a symbol other than . to indicate fully qualiified name access, eg:
    strappend::strJoin (as in C++) or strappend@strJoin where that symbol would bind stronger than . so that it'd work in UFCS chains, eg: getFoo.std::getBar.baz()
    (as originally suggested here: https://github.com/nim-lang/Nim/issues/8013#issuecomment-413332220)
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

2 participants