Skip to content

Commit 1d7e528

Browse files
committed
compile: fix continue in with block
1 parent e2cd6ef commit 1d7e528

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compile/compile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ func (c *compiler) with(node *ast.With, pos int) {
659659
c.Jump(vm.SETUP_WITH, finally)
660660

661661
/* SETUP_WITH pushes a finally block. */
662+
c.loops.Push(loop{Type: finallyTryLoop})
662663
if item.OptionalVars != nil {
663664
c.Expr(item.OptionalVars)
664665
} else {
@@ -676,6 +677,7 @@ func (c *compiler) with(node *ast.With, pos int) {
676677

677678
/* End of try block; start the finally block */
678679
c.Op(vm.POP_BLOCK)
680+
c.loops.Pop()
679681
c.LoadConst(py.None)
680682

681683
/* Finally block starts; context.__exit__ is on the stack under

compile/compile_data_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5633,6 +5633,23 @@ var compileTestData = []struct {
56335633
}, nil, ""},
56345634
{"while truth():\n try:\n f()\n finally:\n continue\n ", "exec", nil, py.SyntaxError, "'continue' not supported inside 'finally' clause"},
56355635
{"while truth():\n try:\n f()\n finally:\n try:\n continue\n except:\n pass\n ", "exec", nil, py.SyntaxError, "'continue' not supported inside 'finally' clause"},
5636+
{"while x:\n with c:\n continue\n ", "exec", &py.Code{
5637+
Argcount: 0,
5638+
Kwonlyargcount: 0,
5639+
Nlocals: 0,
5640+
Stacksize: 8,
5641+
Flags: 64,
5642+
Code: "\x78\x1a\x00\x65\x00\x00\x72\x1c\x00\x65\x01\x00\x8f\x08\x00\x01\x77\x03\x00\x57\x64\x00\x00\x51\x58\x71\x03\x00\x57\x64\x00\x00\x53",
5643+
Consts: []py.Object{py.None},
5644+
Names: []string{"x", "c"},
5645+
Varnames: []string{},
5646+
Freevars: []string{},
5647+
Cellvars: []string{},
5648+
Filename: "<string>",
5649+
Name: "<module>",
5650+
Firstlineno: 1,
5651+
Lnotab: "\x09\x01\x07\x01",
5652+
}, nil, ""},
56365653
{"print(\"hello world!\")\n", "single", &py.Code{
56375654
Argcount: 0,
56385655
Kwonlyargcount: 0,

compile/make_compile_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ def f():
592592
except:
593593
pass
594594
''', "exec", SyntaxError),
595+
('''\
596+
while x:
597+
with c:
598+
continue
599+
''', "exec"),
595600
# interactive
596601
('''print("hello world!")\n''', "single"),
597602
# FIXME ('''if True:\n "hello world!"\n''', "single"),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy