From 6257068ccc315251d62092544c3c734225923881 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 14 Aug 2017 16:19:48 -0400 Subject: [PATCH] deprecate `const` on local variables, which used to be ignored. part of #5148 --- NEWS.md | 3 +++ src/julia-syntax.scm | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 02a4cb0beb31b1..4f001ae743fece 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ---------------- diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index e6481ffdefe2d0..10b919e94798b1 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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))))) @@ -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