Skip to content

Commit e4f408e

Browse files
authored
fix #29429, make local-sparam conflict an error instead of warning (#30184)
1 parent 4b270b1 commit e4f408e

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
@@ -16,6 +16,8 @@ Language changes
1616
* Big integer literals and command syntax (backticks) are now parsed with the name of
1717
the macro (`@int128_str`, `@uint128_str`, `@big_str`, `@cmd`) qualified to refer
1818
to the `Core` module ([#29968]).
19+
* Using the same name for both a local variable and a static parameter is now an error instead
20+
of a warning ([#29429]).
1921

2022
New library functions
2123
---------------------

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
@@ -1556,21 +1556,13 @@ end
15561556
end
15571557
@test A27807.@m()(1,1.0) === (1, 0.0)
15581558

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

15751567
# issue #28044
15761568
code28044(x) = 10x

0 commit comments

Comments
 (0)