Skip to content

Commit fc15ae8

Browse files
committed
Check nargs for builtins (fixes #217)
1 parent c04924e commit fc15ae8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/generate_builtins.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ end
3131
function generate_fcall_nargs(fname, minarg, maxarg)
3232
# Generate a separate call for each number of arguments
3333
maxarg < typemax(Int) || error("call this only for constrained number of arguments")
34-
wrapper = minarg == maxarg ? "" : "if nargs == "
34+
wrapper = "if nargs == "
3535
for nargs = minarg:maxarg
36-
if minarg < maxarg
37-
wrapper *= "$nargs\n "
38-
end
36+
wrapper *= "$nargs\n "
3937
argcall = ""
4038
for i = 1:nargs
4139
argcall *= "@lookup(frame, args[$(i+1)])"
@@ -48,9 +46,9 @@ function generate_fcall_nargs(fname, minarg, maxarg)
4846
wrapper *= "\n elseif nargs == "
4947
end
5048
end
51-
if minarg < maxarg
52-
wrapper *= "\n end"
53-
end
49+
wrapper *= "\n else"
50+
wrapper *= "\n return Some{Any}($fname(getargs(args, frame)...))" # to throw the correct error
51+
wrapper *= "\n end"
5452
return wrapper
5553
end
5654

test/interpret.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,8 @@ try
441441
@test occursin("[4] g_1(::Float64) at $(@__FILE__):$(line_g - 3)", stacktrace_lines[6])
442442
finally
443443
break_off(:error)
444-
end
444+
end
445+
446+
# Check #args for builtins (#217)
447+
f217() = Core._typevar(:foo, Union{}, Any, "foo")
448+
@test_throws ArgumentError @interpret(f217())

0 commit comments

Comments
 (0)