| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1907,9 +1907,6 @@ def error2(): | |||
| 1907 | 1907 | """ | |
| 1908 | 1908 | self._check_error(source, "parameter and nonlocal", lineno=3) | |
| 1909 | 1909 | ||
| 1910 | - def test_break_outside_loop(self): | ||
| 1911 | - self._check_error("break", "outside loop") | ||
| 1912 | - | ||
| 1913 | 1910 | def test_yield_outside_function(self): | |
| 1914 | 1911 | self._check_error("if 0: yield", "outside function") | |
| 1915 | 1912 | self._check_error("if 0: yield\nelse: x=1", "outside function") | |
@@ -1938,20 +1935,27 @@ def test_return_outside_function(self): | |||
| 1938 | 1935 | "outside function") | |
| 1939 | 1936 | ||
| 1940 | 1937 | def test_break_outside_loop(self): | |
| 1941 | - self._check_error("if 0: break", "outside loop") | ||
| 1942 | - self._check_error("if 0: break\nelse: x=1", "outside loop") | ||
| 1943 | - self._check_error("if 1: pass\nelse: break", "outside loop") | ||
| 1944 | - self._check_error("class C:\n if 0: break", "outside loop") | ||
| 1938 | + msg = "outside loop" | ||
| 1939 | + self._check_error("break", msg, lineno=1) | ||
| 1940 | + self._check_error("if 0: break", msg, lineno=1) | ||
| 1941 | + self._check_error("if 0: break\nelse: x=1", msg, lineno=1) | ||
| 1942 | + self._check_error("if 1: pass\nelse: break", msg, lineno=2) | ||
| 1943 | + self._check_error("class C:\n if 0: break", msg, lineno=2) | ||
| 1945 | 1944 | self._check_error("class C:\n if 1: pass\n else: break", | |
| 1946 | - "outside loop") | ||
| 1945 | + msg, lineno=3) | ||
| 1946 | + self._check_error("with object() as obj:\n break", | ||
| 1947 | + msg, lineno=2) | ||
| 1947 | 1948 | ||
| 1948 | 1949 | def test_continue_outside_loop(self): | |
| 1949 | - self._check_error("if 0: continue", "not properly in loop") | ||
| 1950 | - self._check_error("if 0: continue\nelse: x=1", "not properly in loop") | ||
| 1951 | - self._check_error("if 1: pass\nelse: continue", "not properly in loop") | ||
| 1952 | - self._check_error("class C:\n if 0: continue", "not properly in loop") | ||
| 1950 | + msg = "not properly in loop" | ||
| 1951 | + self._check_error("if 0: continue", msg, lineno=1) | ||
| 1952 | + self._check_error("if 0: continue\nelse: x=1", msg, lineno=1) | ||
| 1953 | + self._check_error("if 1: pass\nelse: continue", msg, lineno=2) | ||
| 1954 | + self._check_error("class C:\n if 0: continue", msg, lineno=2) | ||
| 1953 | 1955 | self._check_error("class C:\n if 1: pass\n else: continue", | |
| 1954 | - "not properly in loop") | ||
| 1956 | + msg, lineno=3) | ||
| 1957 | + self._check_error("with object() as obj:\n continue", | ||
| 1958 | + msg, lineno=2) | ||
| 1955 | 1959 | ||
| 1956 | 1960 | def test_unexpected_indent(self): | |
| 1957 | 1961 | self._check_error("foo()\n bar()\n", "unexpected indent", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix wrong lineno in exception message on :keyword:`continue` or | ||
| 2 | + :keyword:`break` which are not in a loop. Patch by Dong-hee Na. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3259,12 +3259,20 @@ static int | |||
| 3259 | 3259 | compiler_break(struct compiler *c) | |
| 3260 | 3260 | { | |
| 3261 | 3261 | struct fblockinfo *loop = NULL; | |
| 3262 | + int u_lineno = c->u->u_lineno; | ||
| 3263 | + int u_col_offset = c->u->u_col_offset; | ||
| 3264 | + int u_end_lineno = c->u->u_end_lineno; | ||
| 3265 | + int u_end_col_offset = c->u->u_end_col_offset; | ||
| 3262 | 3266 | /* Emit instruction with line number */ | |
| 3263 | 3267 | ADDOP(c, NOP); | |
| 3264 | 3268 | if (!compiler_unwind_fblock_stack(c, 0, &loop)) { | |
| 3265 | 3269 | return 0; | |
| 3266 | 3270 | } | |
| 3267 | 3271 | if (loop == NULL) { | |
| 3272 | + c->u->u_lineno = u_lineno; | ||
| 3273 | + c->u->u_col_offset = u_col_offset; | ||
| 3274 | + c->u->u_end_lineno = u_end_lineno; | ||
| 3275 | + c->u->u_end_col_offset = u_end_col_offset; | ||
| 3268 | 3276 | return compiler_error(c, "'break' outside loop"); | |
| 3269 | 3277 | } | |
| 3270 | 3278 | if (!compiler_unwind_fblock(c, loop, 0)) { | |
@@ -3278,12 +3286,20 @@ static int | |||
| 3278 | 3286 | compiler_continue(struct compiler *c) | |
| 3279 | 3287 | { | |
| 3280 | 3288 | struct fblockinfo *loop = NULL; | |
| 3289 | + int u_lineno = c->u->u_lineno; | ||
| 3290 | + int u_col_offset = c->u->u_col_offset; | ||
| 3291 | + int u_end_lineno = c->u->u_end_lineno; | ||
| 3292 | + int u_end_col_offset = c->u->u_end_col_offset; | ||
| 3281 | 3293 | /* Emit instruction with line number */ | |
| 3282 | 3294 | ADDOP(c, NOP); | |
| 3283 | 3295 | if (!compiler_unwind_fblock_stack(c, 0, &loop)) { | |
| 3284 | 3296 | return 0; | |
| 3285 | 3297 | } | |
| 3286 | 3298 | if (loop == NULL) { | |
| 3299 | + c->u->u_lineno = u_lineno; | ||
| 3300 | + c->u->u_col_offset = u_col_offset; | ||
| 3301 | + c->u->u_end_lineno = u_end_lineno; | ||
| 3302 | + c->u->u_end_col_offset = u_end_col_offset; | ||
| 3287 | 3303 | return compiler_error(c, "'continue' not properly in loop"); | |
| 3288 | 3304 | } | |
| 3289 | 3305 | ADDOP_JUMP(c, JUMP, loop->fb_block); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments