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

Error: overloaded 'X' leads to ambiguous calls #12787

Open
zevv opened this issue Dec 1, 2019 · 3 comments
Open

Error: overloaded 'X' leads to ambiguous calls #12787

zevv opened this issue Dec 1, 2019 · 3 comments

Comments

@zevv
Copy link
Contributor

zevv commented Dec 1, 2019

Discussing the snippet below on #nim it was suggested this was worth filing an issue.

My expectation was that it would be fine to do this:

import strutils

proc parse[T: int](s: string): T = parseInt(s)
proc parse[T: float](s: string): T = parseFloat(s)
proc parse[T: bool](s: string): T = parseBool(s)

as long as the caller is explicitly matching one of the signatures like so:

let a parse[int]("42")

However, compilation fails with:

# /tmp/t.nim(4, 6) Error: overloaded 'parse' leads to ambiguous calls

Are my expectations wrong, and if so, which part of the manual did I not read well enough?

The suggestion "Don't do that; it's stupid" also has come up, which I would also take for an answer.

@Araq
Copy link
Member

Araq commented Dec 3, 2019

It's just a compiler bug, nothing wrong with the code.

@timotheecour
Copy link
Member

  • reduced:
when true:
  proc fn[T: int](): T = discard
  proc fn[T: bool](): T = discard

=> Error: overloaded 'fn' leads to ambiguous calls

  • works if generic can be deduced from params:
when true:
  proc fn[T: int](a: T): T = discard
  proc fn[T: bool](a: T): T = discard
  • works if using typedesc:
when true:
  proc fn(T: typedesc[int]): T = discard
  proc fn(T: typedesc[bool]): T = discard

refs nim-lang/RFCs#40

@metagn
Copy link
Collaborator

metagn commented Aug 24, 2024

The problem is in searchForProc, it thinks it's redefining the other parse procs because it doesn't check if the generic params are different

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

4 participants