diff --git a/NEWS.md b/NEWS.md index fd0947d48a3b5..fdfa82dac7ffa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,8 @@ Language changes * Big integer literals and command syntax (backticks) are now parsed with the name of the macro (`@int128_str`, `@uint128_str`, `@big_str`, `@cmd`) qualified to refer to the `Core` module ([#29968]). + * Using the same name for both a local variable and a static parameter is now an error instead + of a warning ([#29429]). New library functions --------------------- diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 65d443440c9c3..eabd575e7b7fb 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -2513,6 +2513,11 @@ (if (memq v argnames) (error (string "local variable name \"" v "\" conflicts with an argument")))) locals-declared))) + (if (and (pair? sp) (eq? e (lam:body lam))) + (for-each (lambda (v) + (if (memq v all-vars) + (error (string "local variable name \"" v "\" conflicts with a static parameter")))) + sp)) (if lam ;; update in-place the list of local variables in lam (set-car! (cddr lam) (append real-new-vars real-new-vars-def (caddr lam)))) diff --git a/src/method.c b/src/method.c index 83cc4fabd1783..a1b6eea18d4d8 100644 --- a/src/method.c +++ b/src/method.c @@ -640,29 +640,6 @@ static jl_method_t *jl_new_method( void print_func_loc(JL_STREAM *s, jl_method_t *m); -static void jl_check_static_parameter_conflicts(jl_method_t *m, jl_code_info_t *src, jl_svec_t *t) -{ - size_t nvars = jl_array_len(src->slotnames); - - size_t i, n = jl_svec_len(t); - for (i = 0; i < n; i++) { - jl_value_t *tv = jl_svecref(t, i); - size_t j; - for (j = 0; j < nvars; j++) { - if (jl_is_typevar(tv)) { - if ((jl_sym_t*)jl_array_ptr_ref(src->slotnames, j) == ((jl_tvar_t*)tv)->name) { - jl_printf(JL_STDERR, - "WARNING: local variable %s conflicts with a static parameter in %s", - jl_symbol_name(((jl_tvar_t*)tv)->name), - jl_symbol_name(m->name)); - print_func_loc(JL_STDERR, m); - jl_printf(JL_STDERR, ".\n"); - } - } - } - } -} - // empty generic function def JL_DLLEXPORT jl_value_t *jl_generic_function_def(jl_sym_t *name, jl_module_t *module, @@ -818,7 +795,6 @@ JL_DLLEXPORT void jl_method_def(jl_svec_t *argdata, m->line); } - jl_check_static_parameter_conflicts(m, f, tvars); jl_method_table_insert(mt, m, NULL); if (jl_newmeth_tracer) jl_call_tracer(jl_newmeth_tracer, (jl_value_t*)m); diff --git a/test/syntax.jl b/test/syntax.jl index 891eeb5a21956..e9913da9b561b 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -1556,21 +1556,13 @@ end end @test A27807.@m()(1,1.0) === (1, 0.0) -# issue #27896 -let oldstderr = stderr, newstderr, errtxt - try - newstderr = redirect_stderr() - @eval function foo(a::A, b::B) where {A,B} - B = eltype(A) - return convert(B, b) - end - errtxt = @async read(newstderr[1], String) - finally - redirect_stderr(oldstderr) - close(newstderr[2]) +# issue #27896 / #29429 +@test Meta.lower(@__MODULE__, quote + function foo(a::A, b::B) where {A,B} + B = eltype(A) + return convert(B, b) end - @test occursin("WARNING: local variable B conflicts with a static parameter", fetch(errtxt)) -end +end) == Expr(:error, "local variable name \"B\" conflicts with a static parameter") # issue #28044 code28044(x) = 10x