Skip to content

Commit

Permalink
deprecate const on local variables, which used to be ignored.
Browse files Browse the repository at this point in the history
part of #5148
  • Loading branch information
JeffBezanson committed Aug 14, 2017
1 parent aecf426 commit 5ed2f45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Language changes
(`need_to_handle_undef_sparam = Set{Any}(m.sig for m in Test.detect_unbound_args(Base, recursive=true))`)
is equal (`==`) to some known set (`expected = Set()`). ([#23117])

* `const` declarations on local variables were previously ignored. They now give a
warning, so that this syntax can be disallowed or given a new meaning in a
future version ([#5148]).

Breaking changes
----------------
Expand Down
3 changes: 2 additions & 1 deletion doc/src/manual/variables-and-scoping.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ their values (or even their types) might change at almost any time. If a global
not change, adding a `const` declaration solves this performance problem.

Local constants are quite different. The compiler is able to determine automatically when a local
variable is constant, so local constant declarations are not necessary, and are currently just ignored.
variable is constant, so local constant declarations are not necessary, and in fact are currently
not supported.

Special top-level assignments, such as those performed by the `function` and `struct` keywords,
are constant by default.
Expand Down
15 changes: 9 additions & 6 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3115,11 +3115,7 @@ f(x) = yt(x)
(if (vinfo:never-undef vi)
'(null)
`(newvar ,(cadr e))))))
((const)
(if (or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
'(null)
e))
((const) e)
((isdefined) ;; convert isdefined expr to function for closure converted variables
(let* ((sym (cadr e))
(vi (and (symbol? sym) (assq sym (car (lam:vinfo lam)))))
Expand Down Expand Up @@ -3661,7 +3657,14 @@ f(x) = yt(x)
((local-def) #f)
((local) #f)
((implicit-global) #f)
((const) (emit e))
((const)
(if (or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
(begin
(syntax-deprecation #f (string "`const` declaration on local variable" (linenode-string current-loc))
"")
'(null))
(emit e)))
((isdefined) (if tail (emit-return e) e))

;; top level expressions returning values
Expand Down

0 comments on commit 5ed2f45

Please sign in to comment.