diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 0039a05188a7e..381074c49bc7f 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -2450,14 +2450,13 @@ (if scope (cond ((memq e (scope:args scope)) e) ((memq e (scope:globals scope)) `(outerref ,e)) - ((memq e (scope:sp scope)) e) (else (let ((r (assq e (scope:renames scope)))) - (if r - (cdr r) - (if (memq e (scope:locals scope)) - e - (lookup (scope:prev scope))))))) + (cond (r (cdr r)) + ((memq e (scope:locals scope)) e) + ((memq e (scope:sp scope)) e) + (else + (lookup (scope:prev scope))))))) (if (underscore-symbol? e) e `(outerref ,e))))) @@ -2532,11 +2531,12 @@ (if (memq v argnames) (error (string "local variable name \"" v "\" conflicts with an argument")))) local-decls)) - (if (eq? e (lam:body lam)) - (for-each (lambda (v) - (if (or (memq v locals-def) (memq v local-decls) (memq v implicit-locals)) - (error (string "local variable name \"" v "\" conflicts with a static parameter")))) - (scope:sp scope))) + (for-each (lambda (lst) + (for-each (lambda (v) + (if (eq? (var-kind v scope) 'static-parameter) + (error (string "local variable name \"" v "\" conflicts with a static parameter")))) + lst)) + (list local-decls implicit-locals)) (if lam (set-car! (cddr lam) (append (caddr lam) newnames newnames-def))) diff --git a/test/syntax.jl b/test/syntax.jl index be967be30a06e..0ca01dc42c648 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -1563,6 +1563,23 @@ end return convert(B, b) end end) == Expr(:error, "local variable name \"B\" conflicts with a static parameter") +# issue #32620 +@test Meta.lower(@__MODULE__, quote + function foo(a::T) where {T} + for i = 1:1 + T = 0 + end + end +end) == Expr(:error, "local variable name \"T\" conflicts with a static parameter") +function f32620(x::T) where T + local y + let T = 3 + T = 2 + y = T + end + return (T, y) +end +@test f32620(0) === (Int, 2) # issue #28044 code28044(x) = 10x