Closed
Description
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment