summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-09-08 16:31:24 (GMT)
committerFred Drake <fdrake@acm.org>2000-09-08 16:31:24 (GMT)
commitfd1f1be98dfe66cd16d2e404e046ec462699dded (patch)
treef006e7ceb96b094ef9d4259073ac5b1728b51500
parent0d8ce6111c16c23c87afc2b06e60bb1b61f75746 (diff)
downloadcpython-fd1f1be98dfe66cd16d2e404e046ec462699dded.zip
cpython-fd1f1be98dfe66cd16d2e404e046ec462699dded.tar.gz
cpython-fd1f1be98dfe66cd16d2e404e046ec462699dded.tar.bz2
com_continue_stmt(): Improve error message when continue is found
in a try statement in a loop. This is related to SourceForge bug #110830.
-rw-r--r--Python/compile.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 155761f..0409f2d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -258,7 +258,7 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
/* Data structure used internally */
struct compiling {
- PyObject *c_code; /* string */
+ PyObject *c_code; /* string */
PyObject *c_consts; /* list of objects */
PyObject *c_const_dict; /* inverse of c_consts */
PyObject *c_names; /* list of strings (names) */
@@ -2933,7 +2933,28 @@ com_continue_stmt(struct compiling *c, node *n)
if (i-- > 0 && c->c_block[i] == SETUP_LOOP) {
com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
}
+ else if (i <= 0) {
+ /* at the outer level */
+ com_error(c, PyExc_SyntaxError,
+ "'continue' not properly in loop");
+ }
else {
+ int j;
+ for (j = 0; j <= i; ++j) {
+ if (c->c_block[j] == SETUP_LOOP)
+ break;
+ }
+ if (j < i+1) {
+ /* there is a loop, but something interferes */
+ for (++j; j <= i; ++j) {
+ if (c->c_block[i] == SETUP_EXCEPT
+ || c->c_block[i] == SETUP_FINALLY) {
+ com_error(c, PyExc_SyntaxError,
+ "'continue' not supported inside 'try' clause");
+ return;
+ }
+ }
+ }
com_error(c, PyExc_SyntaxError,
"'continue' not properly in loop");
}