Skip to content

Commit

Permalink
fix JuliaLang#29429, make local-sparam conflict an error instead of w…
Browse files Browse the repository at this point in the history
…arning (JuliaLang#30184)
  • Loading branch information
JeffBezanson authored Nov 29, 2018
1 parent 4b270b1 commit e4f408e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 38 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand Down
5 changes: 5 additions & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
24 changes: 0 additions & 24 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 6 additions & 14 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e4f408e

Please sign in to comment.