[pypy-svn] r32629 - in pypy/dist/pypy/interpreter: astcompiler test

ac at codespeak.net ac at codespeak.net
Mon Sep 25 15:08:09 CEST 2006


Author: ac
Date: Mon Sep 25 15:08:08 2006
New Revision: 32629

Modified:
   pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
   pypy/dist/pypy/interpreter/test/test_compiler.py
Log:
Fix issue #247.

Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	Mon Sep 25 15:08:08 2006
@@ -504,6 +504,9 @@
                 kind, loop_block = self.setups[top]
                 if kind == LOOP:
                     break
+                elif kind == END_FINALLY:
+                    msg = "'continue' not supported inside 'finally' clause"
+                    raise SyntaxError( msg, node.lineno )
             if kind != LOOP:
                 raise SyntaxError( "'continue' not properly in loop", node.lineno)
             self.emitop_block('CONTINUE_LOOP', loop_block)

Modified: pypy/dist/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_compiler.py	Mon Sep 25 15:08:08 2006
@@ -402,6 +402,34 @@
         space.exec_(code, w_d, w_d)
         assert space.int_w(space.getitem(w_d, space.wrap('result'))) == 42
 
+    def test_continue_in_finally(self):
+        space = self.space
+        snippet = str(py.code.Source(r'''
+def test():
+    for abc in range(10):
+        try: pass
+        finally:
+            continue       # 'continue' inside 'finally'
+
+        '''))
+        space.raises_w(space.w_SyntaxError, self.compiler.compile,
+                       snippet, '<tmp>', 'exec', 0)
+
+    def test_continue_in_nested_finally(self):
+        space = self.space
+        snippet = str(py.code.Source(r'''
+def test():
+    for abc in range(10):
+        try: pass
+        finally:
+            try:
+                continue       # 'continue' inside 'finally'
+            except:
+                pass
+        '''))
+        space.raises_w(space.w_SyntaxError, self.compiler.compile,
+                       snippet, '<tmp>', 'exec', 0)
+
 class TestECCompiler(BaseTestCompiler):
     def setup_method(self, method):
         self.compiler = self.space.getexecutioncontext().compiler
@@ -416,6 +444,10 @@
         test_unicodeliterals = skip_on_2_3
         test_none_assignment = skip_on_2_3
         test_import = skip_on_2_3
+    elif sys.version_info < (2, 5):
+        def skip_on_2_4(self):
+            py.test.skip("syntax not supported by the CPython 2.4 compiler")
+        test_continue_in_nested_finally = skip_on_2_4
 
 class TestPythonAstCompiler(BaseTestCompiler):
     def setup_method(self, method):



More information about the Pypy-commit mailing list