From f261976d898b9001dca216d3f7d3504e9ee67d16 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 31 Mar 2020 16:30:31 +0200 Subject: [PATCH] fix method error printing for missing (#35315) fix method error printing for missing --- base/errorshow.jl | 4 ++-- test/missing.jl | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index c9863f1302a24..7f82bb19c1d23 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -317,7 +317,7 @@ function showerror(io::IO, ex::MethodError) kwargs = pairs(ex.args[1]) ex = MethodError(f, ex.args[3:end]) end - if f == Base.convert && length(arg_types_param) == 2 && !is_arg_types + if f === Base.convert && length(arg_types_param) == 2 && !is_arg_types f_is_function = true show_convert_error(io, ex, arg_types_param) elseif isempty(methods(f)) && isa(f, DataType) && f.abstract @@ -351,7 +351,7 @@ function showerror(io::IO, ex::MethodError) print(io, ")") end # catch the two common cases of element-wise addition and subtraction - if f in (Base.:+, Base.:-) && length(arg_types_param) == 2 + if (f === Base.:+ || f === Base.:-) && length(arg_types_param) == 2 # we need one array of numbers and one number, in any order if any(x -> x <: AbstractArray{<:Number}, arg_types_param) && any(x -> x <: Number, arg_types_param) diff --git a/test/missing.jl b/test/missing.jl index 80dd05f4b8081..d38cab1a2a9a1 100644 --- a/test/missing.jl +++ b/test/missing.jl @@ -527,3 +527,8 @@ mutable struct Obj; x; end @test ismissing(wref[1] == missing) @test ismissing(missing == wref[1]) end + +@testset "showerror missing function" begin + me = try missing(1) catch e e end + @test sprint(showerror, me) == "MethodError: objects of type Missing are not callable" +end