diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-27 05:15:57 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-27 05:15:57 (GMT) |
commit | be77cf7d57ac1e7e4262d919165471de93f3c2ab (patch) | |
tree | a85d6383360ef45e10bbe8532f3226b2eb425336 | |
parent | a35c688055c72e9442f6a82c3ec0e09654077975 (diff) | |
download | cpython-be77cf7d57ac1e7e4262d919165471de93f3c2ab.zip cpython-be77cf7d57ac1e7e4262d919165471de93f3c2ab.tar.gz cpython-be77cf7d57ac1e7e4262d919165471de93f3c2ab.tar.bz2 |
Add warnings about undefined "global"
SF bug #233532
XXX Can't figure out how to write test cases that work with warnings
-rw-r--r-- | Python/compile.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index 3624936..5de2362 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4853,6 +4853,35 @@ symtable_global(struct symtable *st, node *n) for (i = 1; i < NCH(n); i += 2) { char *name = STR(CHILD(n, i)); + int flags; + + flags = symtable_lookup(st, name); + if (flags && flags != DEF_GLOBAL) { + char buf[500]; + if (flags & DEF_PARAM) { + PyErr_Format(PyExc_SyntaxError, + "name '%.400s' is local and global", + PyString_AS_STRING(name)); + set_error_location(st->st_filename, + st->st_cur->ste_lineno); + st->st_errors++; + return; + } else if (flags & DEF_LOCAL) { + sprintf(buf, GLOBAL_AFTER_ASSIGN, name); + if (PyErr_Warn(PyExc_SyntaxWarning, + buf) < 0) { + /* XXX set line number? */ + st->st_errors++; + } + } else { + sprintf(buf, GLOBAL_AFTER_USE, name); + if (PyErr_Warn(PyExc_SyntaxWarning, + buf) < 0) { + /* XXX set line number? */ + st->st_errors++; + } + } + } symtable_add_def(st, name, DEF_GLOBAL); } } |