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

Ambiguous method error when using invoke with kwargs #44227

Closed
JackDunnNZ opened this issue Feb 17, 2022 · 2 comments · Fixed by #44464
Closed

Ambiguous method error when using invoke with kwargs #44227

JackDunnNZ opened this issue Feb 17, 2022 · 2 comments · Fixed by #44464
Assignees
Labels

Comments

@JackDunnNZ
Copy link
Contributor

I ran into the following error that seems to be a bug? Minimal example:

abstract type S1 end
struct S2 <: S1 end

abstract type F end
F(x::S1; y=1, kwargs...) = 1
F(x::S2; y=1, kwargs...) = invoke(F, Tuple{S1}, x; y, kwargs...)

F(S2())

gives

ERROR: MethodError: (::Core.var"#Type##kw")(::NamedTuple, ::DataType, ::S1) is ambiguous. Candidates:
  (::Core.var"#Type##kw")(::Any, ::Type{F}, x::S2) in Main at REPL[5]:1
  (::Core.var"#Type##kw")(::Any, ::Type{F}, x::S1) in Main at REPL[4]:1
...

If the call is a function rather than an abstract type, it works:

f(x::S1; y=1, kwargs...) = 1
f(x::S2; y=1, kwargs...) = invoke(f, Tuple{S1}, x; y, kwargs...)

f(S2())

Similarly, if the y variable is not passed to invoke, it works:

abstract type G end
G(x::S1; y=1, kwargs...) = 1
G(x::S2; y=1, kwargs...) = invoke(G, Tuple{S1}, x; kwargs...)

G(S2())

So it seems to be some interaction between these two things

This was on nightly, but I see the same thing on 1.6 and 1.7

julia> versioninfo()
Julia Version 1.8.0-DEV.1527
Commit ea84398a3d (2022-02-13 19:46 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: 16 × Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 16 virtual cores
@vtjnash vtjnash self-assigned this Feb 17, 2022
vtjnash added a commit that referenced this issue Feb 17, 2022
@fingolfin
Copy link
Member

@vtjnash sorry to bother you, but I noticed made a commit f2e5879 purportedly fixing this, but it's not in any PR as far as I can tell. Is that intentional?

@vtjnash
Copy link
Member

vtjnash commented Mar 5, 2022

oh, I don't know what happened to this

vtjnash added a commit that referenced this issue Mar 8, 2022
vtjnash added a commit that referenced this issue Mar 8, 2022
KristofferC pushed a commit that referenced this issue Mar 11, 2022
KristofferC pushed a commit that referenced this issue Mar 15, 2022
KristofferC pushed a commit that referenced this issue Mar 16, 2022
KristofferC pushed a commit that referenced this issue Apr 19, 2022
staticfloat pushed a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants