From 836992262a7d39eaccce3ec88fe178d6a534f80f Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Mon, 30 Mar 2020 20:36:59 +0200 Subject: [PATCH 1/2] fix method errors 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..e7e3993388366 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, e) == "MethodError: objects of type Missing are not callable" +end From 3aa34cd0f8b99788505ba2199b3bce529ba0e71f Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 31 Mar 2020 13:06:42 +0200 Subject: [PATCH 2/2] fix typo --- test/missing.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/missing.jl b/test/missing.jl index e7e3993388366..d38cab1a2a9a1 100644 --- a/test/missing.jl +++ b/test/missing.jl @@ -530,5 +530,5 @@ end @testset "showerror missing function" begin me = try missing(1) catch e e end - @test sprint(showerror, e) == "MethodError: objects of type Missing are not callable" + @test sprint(showerror, me) == "MethodError: objects of type Missing are not callable" end