Skip to content

Commit

Permalink
Fix showerror for keyword arguments error when the function is not in…
Browse files Browse the repository at this point in the history
… Main or Base
  • Loading branch information
yuyichao committed Jul 16, 2016
1 parent 2d973d0 commit ae0a18a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function _subtypes(m::Module, x::DataType, sts=Set(), visited=Set())
push!(visited, m)
for s in names(m,true)
if isdefined(m,s)
t = eval(m,s)
t = getfield(m, s)
if isa(t, DataType) && t.name.name == s && supertype(t).name == x.name
ti = typeintersect(t, x)
ti != Bottom && push!(sts, ti)
Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function showerror(io::IO, ex::MethodError)
name = ft.name.mt.name
f_is_function = false
kwargs = Any[]
if startswith(string(ft.name), "#kw#")
if startswith(string(ft.name.name), "#kw#")
f = ex.args[2]
ft = typeof(f)
name = ft.name.mt.name
Expand Down
17 changes: 17 additions & 0 deletions test/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,31 @@ m_error = try method_c6(1, x=1) catch e; e; end
showerror(buf, m_error)
error_out1 = takebuf_string(buf)

module TestKWError
method_c6_in_module(; x=1) = x
method_c6_in_module(a; y=1) = y
end
m_error = try TestKWError.method_c6_in_module(y=1) catch e; e; end
showerror(buf, m_error)
error_out2 = takebuf_string(buf)
m_error = try TestKWError.method_c6_in_module(1, x=1) catch e; e; end
showerror(buf, m_error)
error_out3 = takebuf_string(buf)

if Base.have_color
@test contains(error_out, "method_c6(; x)\e[1m\e[31m got an unsupported keyword argument \"y\"\e[0m")
@test contains(error_out, "method_c6(\e[1m\e[31m::Any\e[0m; y)")
@test contains(error_out1, "method_c6(::Any; y)\e[1m\e[31m got an unsupported keyword argument \"x\"\e[0m")
@test contains(error_out2, "method_c6_in_module(; x)\e[1m\e[31m got an unsupported keyword argument \"y\"\e[0m")
@test contains(error_out2, "method_c6_in_module(\e[1m\e[31m::Any\e[0m; y)")
@test contains(error_out3, "method_c6_in_module(::Any; y)\e[1m\e[31m got an unsupported keyword argument \"x\"\e[0m")
else
@test contains(error_out, "method_c6(; x) got an unsupported keyword argument \"y\"")
@test contains(error_out, "method_c6(!Matched::Any; y)")
@test contains(error_out1, "method_c6(::Any; y) got an unsupported keyword argument \"x\"")
@test contains(error_out2, "method_c6_in_module(; x) got an unsupported keyword argument \"y\"")
@test contains(error_out2, "method_c6_in_module(!Matched::Any; y)")
@test contains(error_out3, "method_c6_in_module(::Any; y) got an unsupported keyword argument \"x\"")
end

method_c7(a, b; kargs...) = a
Expand Down

0 comments on commit ae0a18a

Please sign in to comment.