Skip to content

Commit 34e6035

Browse files
authored
fix method definition error for bad vararg (#51300)
We had the ordering of tests incorrect, so Vararg was not correctly checked for validity during method definition. Fixes #51228
1 parent e9d9314 commit 34e6035

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/method.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,16 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
10441044

10451045
for (i = 0; i < na; i++) {
10461046
jl_value_t *elt = jl_svecref(atypes, i);
1047-
int isvalid = jl_is_type(elt) || jl_is_typevar(elt) || jl_is_vararg(elt);
1048-
if (elt == jl_bottom_type || (jl_is_vararg(elt) && jl_unwrap_vararg(elt) == jl_bottom_type))
1049-
isvalid = 0;
1047+
if (jl_is_vararg(elt)) {
1048+
if (i < na-1)
1049+
jl_exceptionf(jl_argumenterror_type,
1050+
"Vararg on non-final argument in method definition for %s at %s:%d",
1051+
jl_symbol_name(name),
1052+
jl_symbol_name(file),
1053+
line);
1054+
elt = jl_unwrap_vararg(elt);
1055+
}
1056+
int isvalid = (jl_is_type(elt) || jl_is_typevar(elt) || jl_is_vararg(elt)) && elt != jl_bottom_type;
10501057
if (!isvalid) {
10511058
jl_sym_t *argname = (jl_sym_t*)jl_array_ptr_ref(f->slotnames, i);
10521059
if (argname == jl_unused_sym)
@@ -1064,12 +1071,6 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
10641071
jl_symbol_name(file),
10651072
line);
10661073
}
1067-
if (jl_is_vararg(elt) && i < na-1)
1068-
jl_exceptionf(jl_argumenterror_type,
1069-
"Vararg on non-final argument in method definition for %s at %s:%d",
1070-
jl_symbol_name(name),
1071-
jl_symbol_name(file),
1072-
line);
10731074
}
10741075
for (i = jl_svec_len(tvars); i > 0; i--) {
10751076
jl_value_t *tv = jl_svecref(tvars, i - 1);

test/syntax.jl

+4
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ let m_error, error_out, filename = Base.source_path()
501501
m_error = try @eval foo(types::NTuple{N}, values::Vararg{Any,N}, c) where {N} = nothing; catch e; e; end
502502
error_out = sprint(showerror, m_error)
503503
@test startswith(error_out, "ArgumentError: Vararg on non-final argument")
504+
505+
m_error = try @eval method_c6(a::Vararg{:A}) = 1; catch e; e; end
506+
error_out = sprint(showerror, m_error)
507+
@test startswith(error_out, "ArgumentError: invalid type for argument a in method definition for method_c6 at $filename:")
504508
end
505509

506510
# issue #7272

0 commit comments

Comments
 (0)