Skip to content

Commit 28d8b80

Browse files
committed
slightly improve error message for unsupported kw arguments
also fix some code formatting
1 parent b066714 commit 28d8b80

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

base/replutil.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ function show_method_candidates(io::IO, ex::MethodError, kwargs::Vector=Any[])
533533
end
534534
if !isempty(unexpected)
535535
Base.with_output_color(:red, buf) do buf
536-
print(buf, " got an unsupported keyword argument \"", join(unexpected, "\", \""), "\"")
536+
plur = length(unexpected) > 1 ? "s" : ""
537+
print(buf, " got unsupported keyword argument$plur \"", join(unexpected, "\", \""), "\"")
537538
end
538539
end
539540
end

src/julia-syntax.scm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,9 @@
522522
,else)))
523523
(if (null? restkw)
524524
;; if no rest kw, give error for unrecognized
525-
`(call (top kwerr) ,kw ,@(map arg-name pargl),@(if (null? vararg) '()
526-
(list `(... ,(arg-name (car vararg))))))
525+
`(call (top kwerr) ,kw ,@(map arg-name pargl)
526+
,@(if (null? vararg) '()
527+
(list `(... ,(arg-name (car vararg))))))
527528
;; otherwise add to rest keywords
528529
`(ccall 'jl_array_ptr_1d_push Void (tuple Any Any)
529530
,rkw (tuple ,elt

test/keywordargs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kwf1(ones; tens=0, hundreds=0) = ones + 10*tens + 100*hundreds
99
@test kwf1(3, tens=7, hundreds=2) == 273
1010

1111
@test_throws MethodError kwf1() # no method, too few args
12-
@test_throws MethodError kwf1(1, z=0) # unsupported keyword
12+
@test_throws MethodError kwf1(1, z=0) # unsupported keyword
1313
@test_throws MethodError kwf1(1, 2) # no method, too many positional args
1414

1515
# keyword args plus varargs

test/replutil.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,19 @@ showerror(buf, m_error)
127127
error_out3 = takebuf_string(buf)
128128

129129
if Base.have_color
130-
@test contains(error_out, "method_c6(; x)$cfile$(c6line + 1)\e[1m\e[31m got an unsupported keyword argument \"y\"\e[0m")
130+
@test contains(error_out, "method_c6(; x)$cfile$(c6line + 1)\e[1m\e[31m got unsupported keyword argument \"y\"\e[0m")
131131
@test contains(error_out, "method_c6(\e[1m\e[31m::Any\e[0m; y)$cfile$(c6line + 2)")
132-
@test contains(error_out1, "method_c6(::Any; y)$cfile$(c6line + 2)\e[1m\e[31m got an unsupported keyword argument \"x\"\e[0m")
133-
@test contains(error_out2, "method_c6_in_module(; x)$cfile$(c6mline + 2)\e[1m\e[31m got an unsupported keyword argument \"y\"\e[0m")
132+
@test contains(error_out1, "method_c6(::Any; y)$cfile$(c6line + 2)\e[1m\e[31m got unsupported keyword argument \"x\"\e[0m")
133+
@test contains(error_out2, "method_c6_in_module(; x)$cfile$(c6mline + 2)\e[1m\e[31m got unsupported keyword argument \"y\"\e[0m")
134134
@test contains(error_out2, "method_c6_in_module(\e[1m\e[31m::Any\e[0m; y)$cfile$(c6mline + 3)")
135-
@test contains(error_out3, "method_c6_in_module(::Any; y)$cfile$(c6mline + 3)\e[1m\e[31m got an unsupported keyword argument \"x\"\e[0m")
135+
@test contains(error_out3, "method_c6_in_module(::Any; y)$cfile$(c6mline + 3)\e[1m\e[31m got unsupported keyword argument \"x\"\e[0m")
136136
else
137-
@test contains(error_out, "method_c6(; x)$cfile$(c6line + 1) got an unsupported keyword argument \"y\"")
137+
@test contains(error_out, "method_c6(; x)$cfile$(c6line + 1) got unsupported keyword argument \"y\"")
138138
@test contains(error_out, "method_c6(!Matched::Any; y)$cfile$(c6line + 2)")
139-
@test contains(error_out1, "method_c6(::Any; y)$cfile$(c6line + 2) got an unsupported keyword argument \"x\"")
140-
@test contains(error_out2, "method_c6_in_module(; x)$cfile$(c6mline + 2) got an unsupported keyword argument \"y\"")
139+
@test contains(error_out1, "method_c6(::Any; y)$cfile$(c6line + 2) got unsupported keyword argument \"x\"")
140+
@test contains(error_out2, "method_c6_in_module(; x)$cfile$(c6mline + 2) got unsupported keyword argument \"y\"")
141141
@test contains(error_out2, "method_c6_in_module(!Matched::Any; y)$cfile$(c6mline + 3)")
142-
@test contains(error_out3, "method_c6_in_module(::Any; y)$cfile$(c6mline + 3) got an unsupported keyword argument \"x\"")
142+
@test contains(error_out3, "method_c6_in_module(::Any; y)$cfile$(c6mline + 3) got unsupported keyword argument \"x\"")
143143
end
144144

145145
c7line = @__LINE__ + 1
@@ -150,16 +150,16 @@ test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c7(::Any, ::Any;
150150
c8line = @__LINE__ + 1
151151
method_c8(a, b; y=1, w=1) = a
152152
Base.show_method_candidates(buf, MethodError(method_c8, (1, 1)), [(:x, 1), (:y, 2), (:z, 1), (:w, 1)])
153-
test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c8(::Any, ::Any; y, w)$cfile$c8line\e[1m\e[31m got an unsupported keyword argument \"x\", \"z\"\e[0m\e[0m",
154-
"\nClosest candidates are:\n method_c8(::Any, ::Any; y, w)$cfile$c8line got an unsupported keyword argument \"x\", \"z\"")
153+
test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c8(::Any, ::Any; y, w)$cfile$c8line\e[1m\e[31m got unsupported keyword arguments \"x\", \"z\"\e[0m\e[0m",
154+
"\nClosest candidates are:\n method_c8(::Any, ::Any; y, w)$cfile$c8line got unsupported keyword arguments \"x\", \"z\"")
155155

156156
ac15639line = @__LINE__
157157
addConstraint_15639(c::Int32) = c
158158
addConstraint_15639(c::Int64; uncset=nothing) = addConstraint_15639(Int32(c), uncset=uncset)
159159

160160
Base.show_method_candidates(buf, MethodError(addConstraint_15639, (Int32(1),)), [(:uncset, nothing)])
161-
test_have_color(buf, "\e[0m\nClosest candidates are:\n addConstraint_15639(::Int32)$cfile$(ac15639line + 1)\e[1m\e[31m got an unsupported keyword argument \"uncset\"\e[0m\n addConstraint_15639(\e[1m\e[31m::Int64\e[0m; uncset)$cfile$(ac15639line + 2)\e[0m",
162-
"\nClosest candidates are:\n addConstraint_15639(::Int32)$cfile$(ac15639line + 1) got an unsupported keyword argument \"uncset\"\n addConstraint_15639(!Matched::Int64; uncset)$cfile$(ac15639line + 2)")
161+
test_have_color(buf, "\e[0m\nClosest candidates are:\n addConstraint_15639(::Int32)$cfile$(ac15639line + 1)\e[1m\e[31m got unsupported keyword argument \"uncset\"\e[0m\n addConstraint_15639(\e[1m\e[31m::Int64\e[0m; uncset)$cfile$(ac15639line + 2)\e[0m",
162+
"\nClosest candidates are:\n addConstraint_15639(::Int32)$cfile$(ac15639line + 1) got unsupported keyword argument \"uncset\"\n addConstraint_15639(!Matched::Int64; uncset)$cfile$(ac15639line + 2)")
163163

164164
macro except_str(expr, err_type)
165165
return quote

0 commit comments

Comments
 (0)