summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compiler_codegen.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2024-02-15 14:32:21 (GMT)
committerGitHub <noreply@github.com>2024-02-15 14:32:21 (GMT)
commit3a9e67a9fdb4fad13bf42df6eb91126ab2ef45a1 (patch)
tree15510e717e5296c461cd51997fe24b426d481b15 /Lib/test/test_compiler_codegen.py
parent94f1334e52fbc1550feba4f433b16589d55255b9 (diff)
downloadcpython-3a9e67a9fdb4fad13bf42df6eb91126ab2ef45a1.zip
cpython-3a9e67a9fdb4fad13bf42df6eb91126ab2ef45a1.tar.gz
cpython-3a9e67a9fdb4fad13bf42df6eb91126ab2ef45a1.tar.bz2
gh-115376: fix segfault in _testinternalcapi.compiler_codegen on bad input (#115379)
Diffstat (limited to 'Lib/test/test_compiler_codegen.py')
-rw-r--r--Lib/test/test_compiler_codegen.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_compiler_codegen.py b/Lib/test/test_compiler_codegen.py
index dbeadd9..166294a 100644
--- a/Lib/test/test_compiler_codegen.py
+++ b/Lib/test/test_compiler_codegen.py
@@ -8,7 +8,7 @@ class IsolatedCodeGenTests(CodegenTestCase):
def codegen_test(self, snippet, expected_insts):
import ast
- a = ast.parse(snippet, "my_file.py", "exec");
+ a = ast.parse(snippet, "my_file.py", "exec")
insts = self.generate_code(a)
self.assertInstructionsMatch(insts, expected_insts)
@@ -54,3 +54,8 @@ class IsolatedCodeGenTests(CodegenTestCase):
('RETURN_VALUE', None),
]
self.codegen_test(snippet, expected)
+
+ def test_syntax_error__return_not_in_function(self):
+ snippet = "return 42"
+ with self.assertRaisesRegex(SyntaxError, "'return' outside function"):
+ self.codegen_test(snippet, None)