From 9a4c0d8017b29b2b89386de0e3def759d0bbf8fb Mon Sep 17 00:00:00 2001 From: Isaiah Norton Date: Thu, 2 Jul 2015 01:21:30 -0400 Subject: [PATCH] disallow nested 'global x' if x is local variable in enclosing scope fixes #7264 --- NEWS.md | 3 +++ src/julia-syntax.scm | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e0288c802cef1..d2c58ee8b654f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -127,6 +127,9 @@ Language changes * Triple-quoted strings no longer treat tabs as 8 spaces. Instead, the longest common prefix of spaces and tabs is removed. + * `global x` in a nested scope is now a syntax error if `x` is local + to the enclosing scope ([#7264]/[#11985]). + Command line option changes --------------------------- diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index d8897576aa38c..6cfa41ae9b447 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -3229,7 +3229,12 @@ So far only the second case can actually occur. (mark-label endl)) )) - ((global) #f) ; remove global declarations + ((global) ; remove global declarations + (let ((vname (cadr e))) + (if (var-info-for vname vi) + ; issue #7264 + (error (string "`global " vname "`: " vname " is local variable in the enclosing scope")) + #f))) ((implicit-global) #f) ((local!) #f) ((jlgensym) #f)