-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Incorrect "Method definition overwritten" error #14960
Comments
It is overwriting the methods. julia> type T
x::Tuple{Int,Int}
end
julia> methods(T)
3-element Array{Any,1}:
T(x::Tuple{Int64,Int64}) at none:2
T(x) at none:2
(::Type{T}){T}(arg) at essentials.jl:25
julia> T(x) = error(x)
WARNING: Method definition (::Type{Main.T})(Any) in module Main at none:2 overwritten at none:1.
T
julia> methods(T)
3-element Array{Any,1}:
T(x::Tuple{Int64,Int64}) at none:2
T(x) at none:1
(::Type{T}){T}(arg) at essentials.jl:25 It might not be very useful though... |
Ah yes, it's overwriting a default constructor. That is indeed kind of unfortunate. |
Good catch, I forgot there's also a constructor with a broad signature. Maybe we'd need the concept of low-priority methods which can be overwritten without a warning. That could also be useful for example to allow delegating most methods for a type to one of its fields (#2248): you would be able to overwrite some methods after the |
I'd like to propose that this issue be categorised as a bug and put on the 0.5.x milestone. I've hit this issue in my own code |
With #11310, it will be easy to put "outer" constructors (i.e. constructors where type parameters have not been specified) inside |
@jiahao Could you clarify? The only "complete fix" I have in mind is to make it syntactically easier to write all constructors inside the type block. I would not want to do something like changing which default constructors we generate or which warnings we give. What fix are you thinking of? |
No warning is printed on current master. |
The error message below (with a recent git master) seems incorrect:
Indeed, the method isn't overwritten at all:
The text was updated successfully, but these errors were encountered: