mirror of
https://github.com/python/cpython.git
synced 2025-10-21 06:02:21 +00:00
com_continue_stmt(): Improve error message when continue is found
in a try statement in a loop. This is related to SourceForge bug #110830.
This commit is contained in:
parent
0d8ce6111c
commit
fd1f1be98d
1 changed files with 22 additions and 1 deletions
|
@ -2933,7 +2933,28 @@ com_continue_stmt(struct compiling *c, node *n)
|
||||||
if (i-- > 0 && c->c_block[i] == SETUP_LOOP) {
|
if (i-- > 0 && c->c_block[i] == SETUP_LOOP) {
|
||||||
com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
|
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 {
|
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,
|
com_error(c, PyExc_SyntaxError,
|
||||||
"'continue' not properly in loop");
|
"'continue' not properly in loop");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue