Skip to content

Commit

Permalink
fix #32620, crash when assigning to static parameter (#32623)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jul 20, 2019
1 parent bb8fefb commit b9b099f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
Expand Down Expand Up @@ -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)))
Expand Down
17 changes: 17 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9b099f

Please sign in to comment.