JuliaLang/julia
View on GitHubMethoderror for constructors should consider typevars
Open
#33,539 opened on Oct 12, 2019
error messageshelp wanted
Repository metrics
- Stars
- (48,709 stars)
- PR merge metrics
- (Avg merge 20d 6h) (157 merged PRs in 30d)
Description
Consider
julia> struct Foo{T,S}
a::S
b::T
end
julia> Foo(1, 2)
Foo{Int64,Int64}(1, 2)
julia> Foo{Int64, Int64}(1, 2)
Foo{Int64,Int64}(1, 2)
julia> Foo{Int64}(1)
ERROR: MethodError: no method matching Foo{Int64,S} where S(::Int64)
Stacktrace:
[1] top-level scope at REPL[4]:1
The MethodError here is missing closest candidates for the implicitly defined constructors.
The reason for that is likely the following:
julia> methods(Foo{Int64})
# 0 methods for type constructor:
julia> methods(Foo)
# 1 method for type constructor:
[1] (::Type{Foo})(a::S, b::T) where {T, S} in Main at REPL[1]:2
julia> methods(Base.unwrap_unionall(Foo))
# 2 methods for type constructor:
[1] (::Type{Foo})(a::S, b::T) where {T, S} in Main at REPL[1]:2
[2] (::Type{Foo{T,S}})(a, b) where {T, S} in Main at REPL[1]:
so one approach to start here might be widening f
in https://github.com/JuliaLang/julia/blob/master/base/errorshow.jl#L350 to Base.unwrap_unionall(Base.unwrap_unionall(Foo{Int64}).name.wrapper) or something similar.