Skip to content

Commit 08fbd73

Browse files
committed
fix #29429, make local-sparam conflict an error instead of warning
1 parent a50d5af commit 08fbd73

File tree

4 files changed

+13
-38
lines changed

4 files changed

+13
-38
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Language changes
1818
Previously they were sometimes parsed as tuples, depending on whitespace ([#28506]).
1919
* `Regex` and `TimeZone` now behave like scalars when used in broadcasting ([#29913], [#30159]).
2020
* `Char` now behaves like a read-only 0-dimensional array ([#29819]).
21+
* Using the same name for both a local variable and a static parameter is now an error instead
22+
of a warning ([#29429]).
2123

2224
New library functions
2325
---------------------

src/julia-syntax.scm

+5
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,11 @@
25132513
(if (memq v argnames)
25142514
(error (string "local variable name \"" v "\" conflicts with an argument"))))
25152515
locals-declared)))
2516+
(if (and (pair? sp) (eq? e (lam:body lam)))
2517+
(for-each (lambda (v)
2518+
(if (memq v all-vars)
2519+
(error (string "local variable name \"" v "\" conflicts with a static parameter"))))
2520+
sp))
25162521
(if lam ;; update in-place the list of local variables in lam
25172522
(set-car! (cddr lam)
25182523
(append real-new-vars real-new-vars-def (caddr lam))))

src/method.c

-24
Original file line numberDiff line numberDiff line change
@@ -640,29 +640,6 @@ static jl_method_t *jl_new_method(
640640

641641
void print_func_loc(JL_STREAM *s, jl_method_t *m);
642642

643-
static void jl_check_static_parameter_conflicts(jl_method_t *m, jl_code_info_t *src, jl_svec_t *t)
644-
{
645-
size_t nvars = jl_array_len(src->slotnames);
646-
647-
size_t i, n = jl_svec_len(t);
648-
for (i = 0; i < n; i++) {
649-
jl_value_t *tv = jl_svecref(t, i);
650-
size_t j;
651-
for (j = 0; j < nvars; j++) {
652-
if (jl_is_typevar(tv)) {
653-
if ((jl_sym_t*)jl_array_ptr_ref(src->slotnames, j) == ((jl_tvar_t*)tv)->name) {
654-
jl_printf(JL_STDERR,
655-
"WARNING: local variable %s conflicts with a static parameter in %s",
656-
jl_symbol_name(((jl_tvar_t*)tv)->name),
657-
jl_symbol_name(m->name));
658-
print_func_loc(JL_STDERR, m);
659-
jl_printf(JL_STDERR, ".\n");
660-
}
661-
}
662-
}
663-
}
664-
}
665-
666643
// empty generic function def
667644
JL_DLLEXPORT jl_value_t *jl_generic_function_def(jl_sym_t *name,
668645
jl_module_t *module,
@@ -818,7 +795,6 @@ JL_DLLEXPORT void jl_method_def(jl_svec_t *argdata,
818795
m->line);
819796
}
820797

821-
jl_check_static_parameter_conflicts(m, f, tvars);
822798
jl_method_table_insert(mt, m, NULL);
823799
if (jl_newmeth_tracer)
824800
jl_call_tracer(jl_newmeth_tracer, (jl_value_t*)m);

test/syntax.jl

+6-14
Original file line numberDiff line numberDiff line change
@@ -1554,21 +1554,13 @@ end
15541554
end
15551555
@test A27807.@m()(1,1.0) === (1, 0.0)
15561556

1557-
# issue #27896
1558-
let oldstderr = stderr, newstderr, errtxt
1559-
try
1560-
newstderr = redirect_stderr()
1561-
@eval function foo(a::A, b::B) where {A,B}
1562-
B = eltype(A)
1563-
return convert(B, b)
1564-
end
1565-
errtxt = @async read(newstderr[1], String)
1566-
finally
1567-
redirect_stderr(oldstderr)
1568-
close(newstderr[2])
1557+
# issue #27896 / #29429
1558+
@test Meta.lower(@__MODULE__, quote
1559+
function foo(a::A, b::B) where {A,B}
1560+
B = eltype(A)
1561+
return convert(B, b)
15691562
end
1570-
@test occursin("WARNING: local variable B conflicts with a static parameter", fetch(errtxt))
1571-
end
1563+
end) == Expr(:error, "local variable name \"B\" conflicts with a static parameter")
15721564

15731565
# issue #28044
15741566
code28044(x) = 10x

0 commit comments

Comments
 (0)