diff Python/compile.c @ 14471:c3c49859e80b legacy-trunk

com_continue_stmt(): Improve error message when continue is found in a try statement in a loop. This is related to SourceForge bug #110830.
author Fred Drake <fdrake@acm.org>
date Fri, 08 Sep 2000 16:31:24 +0000
parents 2d6cf68aa64a
children 25ddd3dc7a7a
line wrap: on
line diff
--- a/Python/compile.c	Fri Sep 08 16:28:30 2000 +0000
+++ b/Python/compile.c	Fri Sep 08 16:31:24 2000 +0000
@@ -258,7 +258,7 @@
 /* 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 @@
 	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");
 	}