Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warning for function declaration with undefined static parameter #46608

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,6 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
size_t i, na = jl_svec_len(atypes);

argtype = (jl_value_t*)jl_apply_tuple_type(atypes);
for (i = jl_svec_len(tvars); i > 0; i--) {
jl_value_t *tv = jl_svecref(tvars, i - 1);
if (!jl_is_typevar(tv))
jl_type_error("method signature", (jl_value_t*)jl_tvar_type, tv);
argtype = jl_new_struct(jl_unionall_type, tv, argtype);
}

jl_methtable_t *external_mt = mt;
if (!mt)
Expand All @@ -972,6 +966,12 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
if (mt->frozen)
jl_error("cannot add methods to a builtin function");

assert(jl_is_linenode(functionloc));
jl_sym_t *file = (jl_sym_t*)jl_linenode_file(functionloc);
if (!jl_is_symbol(file))
file = jl_empty_sym;
int32_t line = jl_linenode_line(functionloc);

// TODO: derive our debug name from the syntax instead of the type
name = mt->name;
if (mt == jl_type_type_mt || mt == jl_nonfunction_mt || external_mt) {
Expand All @@ -988,6 +988,29 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
}
}
}

for (i = jl_svec_len(tvars); i > 0; i--) {
jl_value_t *tv = jl_svecref(tvars, i - 1);
if (!jl_is_typevar(tv))
jl_type_error("method signature", (jl_value_t*)jl_tvar_type, tv);
if (!jl_has_typevar(argtype, (jl_tvar_t*)tv)) // deprecate this to an error in v2
jl_printf(JL_STDERR,
"WARNING: method definition for %s at %s:%d declares type variable %s but does not use it.\n",
jl_symbol_name(name),
jl_symbol_name(file),
line,
jl_symbol_name(((jl_tvar_t*)tv)->name));
argtype = jl_new_struct(jl_unionall_type, tv, argtype);
}
if (jl_has_free_typevars(argtype)) {
jl_exceptionf(jl_argumenterror_type,
"method definition for %s at %s:%d has free type variables",
jl_symbol_name(name),
jl_symbol_name(file),
line);
}


if (!jl_is_code_info(f)) {
// this occurs when there is a closure being added to an out-of-scope function
// the user should only do this at the toplevel
Expand All @@ -1002,20 +1025,10 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
m->name = name;
m->isva = isva;
m->nargs = nargs;
assert(jl_is_linenode(functionloc));
jl_value_t *file = jl_linenode_file(functionloc);
m->file = jl_is_symbol(file) ? (jl_sym_t*)file : jl_empty_sym;
m->line = jl_linenode_line(functionloc);
m->file = file;
m->line = line;
jl_method_set_source(m, f);

if (jl_has_free_typevars(argtype)) {
jl_exceptionf(jl_argumenterror_type,
"method definition for %s at %s:%d has free type variables",
jl_symbol_name(name),
jl_symbol_name(m->file),
m->line);
}

for (i = 0; i < na; i++) {
jl_value_t *elt = jl_svecref(atypes, i);
if (!jl_is_type(elt) && !jl_is_typevar(elt) && !jl_is_vararg(elt)) {
Expand All @@ -1025,22 +1038,22 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
"invalid type for argument number %d in method definition for %s at %s:%d",
i,
jl_symbol_name(name),
jl_symbol_name(m->file),
m->line);
jl_symbol_name(file),
line);
else
jl_exceptionf(jl_argumenterror_type,
"invalid type for argument %s in method definition for %s at %s:%d",
jl_symbol_name(argname),
jl_symbol_name(name),
jl_symbol_name(m->file),
m->line);
jl_symbol_name(file),
line);
}
if (jl_is_vararg(elt) && i < na-1)
jl_exceptionf(jl_argumenterror_type,
"Vararg on non-final argument in method definition for %s at %s:%d",
jl_symbol_name(name),
jl_symbol_name(m->file),
m->line);
jl_symbol_name(file),
line);
}

#ifdef RECORD_METHOD_ORDER
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ BunchKaufman(A::AbstractMatrix{T}, ipiv::AbstractVector{<:Integer}, uplo::Abstra
symmetric::Bool, rook::Bool, info::BlasInt) where {T} =
BunchKaufman{T,typeof(A),typeof(ipiv)}(A, ipiv, uplo, symmetric, rook, info)
# backwards-compatible constructors (remove with Julia 2.0)
@deprecate(BunchKaufman(LD, ipiv, uplo, symmetric, rook, info) where {T,S},
@deprecate(BunchKaufman{T,S}(LD, ipiv, uplo, symmetric, rook, info) where {T,S},
BunchKaufman{T,S,typeof(ipiv)}(LD, ipiv, uplo, symmetric, rook, info), false)

# iteration for destructuring into components
Expand Down