@@ -1749,28 +1749,26 @@ function expand_ccall(ctx, ex)
17491749 end
17501750 arg_types = children (arg_type_tuple)
17511751 vararg_type = nothing
1752+ num_required_args = length (arg_types)
17521753 if length (arg_types) >= 1
17531754 va = arg_types[end ]
17541755 if kind (va) == K " ..."
17551756 @chk numchildren (va) == 1
17561757 # Ok: vararg function
17571758 vararg_type = va
1759+ if length (arg_types) <= 1
1760+ throw (LoweringError (vararg_type, " C ABI prohibits vararg without one required argument" ))
1761+ else
1762+ num_required_args = length (arg_types) - 1
1763+ end
17581764 end
17591765 end
17601766 # todo: use multi-range errors here
1761- if length (args) < length (arg_types)
1767+ if length (args) < num_required_args
17621768 throw (LoweringError (ex, " Too few arguments in ccall compared to argument types" ))
17631769 elseif length (args) > length (arg_types) && isnothing (vararg_type)
17641770 throw (LoweringError (ex, " More arguments than types in ccall" ))
17651771 end
1766- if isnothing (vararg_type)
1767- num_required_args = 0
1768- else
1769- num_required_args = length (arg_types) - 1
1770- if num_required_args < 1
1771- throw (LoweringError (vararg_type, " C ABI prohibits vararg without one required argument" ))
1772- end
1773- end
17741772 sctx = with_stmts (ctx)
17751773 expanded_types = SyntaxList (ctx)
17761774 for (i, argt) in enumerate (arg_types)
@@ -1845,7 +1843,7 @@ function expand_ccall(ctx, ex)
18451843 expanded_types...
18461844 ]
18471845 ]
1848- num_required_args:: K"Integer"
1846+ ( isnothing (vararg_type) ? 0 : num_required_args) :: K"Integer"
18491847 if isnothing (cconv)
18501848 " ccall" :: K"Symbol"
18511849 else
0 commit comments