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

fix #34824, improve various cases of showing method signatures #35862

Merged
merged 2 commits into from
May 15, 2020

Conversation

JeffBezanson
Copy link
Sponsor Member

The code for this was duplicated several times (more than 3, depending how you count), with all sorts of problems. Here are some examples.

Before:

julia> methods(Complex)
# 7 methods for type constructor:
[1] (::Type{Complex})(x::Real) in Base at complex.jl:16
...

julia> methods(Complex{Int})
# 7 methods for type constructor:
[1] (::Type{Complex{T}})(x::AbstractIrrational) where T<:Real in Base at irrationals.jl:34
...

julia> (Complex{T} where T<:Integer)(1.2)
ERROR: MethodError: no method matching Complex{T} where T<:Integer(::Float64)
Closest candidates are:
  Complex{T} where T<:Integer(::T) where T<:Number at boot.jl:715

julia> (::Union{Nothing,Int})(::Nothing) = nothing

julia> nothing("")
ERROR: MethodError: no method matching (::Nothing)(::String)
Closest candidates are:
  Any(::Nothing) at REPL[6]:1

After:

julia> methods(Complex)
# 7 methods for type constructor:
[1] Complex(x::Real) in Base at complex.jl:16
...

julia> methods(Complex{Int})
# 7 methods for type constructor:
[1] Complex{T}(x::AbstractIrrational) where T<:Real in Base at irrationals.jl:47
...

julia> (Complex{T} where T<:Integer)(1.2)
ERROR: MethodError: no method matching (Complex{T} where T<:Integer)(::Float64)
Closest candidates are:
  (::Type{T})(::T) where T<:Number at boot.jl:715

julia> (::Union{Nothing,Int})(::Nothing) = nothing

julia> nothing("")
ERROR: MethodError: no method matching (::Nothing)(::String)
Closest candidates are:
  (::Union{Nothing, Int64})(::Nothing) at REPL[1]:1

Fixes #34824. Replaces #35311.

Discussion questions:

  • I decided to print methods on unionalls as (Foo{T} where T)(x) even though that is not currently valid input syntax. With allow where syntax in constructor definitions #35861 it would be, so I think it's ok.
  • The "closest candidates" printing used to show the called type in the head of each signature, instead of the type from the definition (see third example above). That was probably intentional and I can see a case for it, but I think it's confusing because it looks like it's showing definitions that don't actually exist. I think we should show the same thing that e.g. methods(t) shows.

@JeffBezanson JeffBezanson added kind:bugfix This change fixes an existing bug domain:display and printing Aesthetics and correctness of printed representations of objects. labels May 13, 2020
base/show.jl Show resolved Hide resolved
Co-authored-by: Jameson Nash <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid error message for type parameter
2 participants