Commit c00a745e authored by Marius Wachtler's avatar Marius Wachtler

compile: Don't check for ''break' outside loop' error when in AST only mode

parent 3a81033b
# expected: fail
import sys, itertools, unittest
from test import test_support
import ast
......
......@@ -490,9 +490,10 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
AST* parsed;
mod_ty mod;
ArenaWrapper arena;
if (PyAST_Check(source)) {
int mode;
ArenaWrapper arena;
if (type_str->s() == "exec")
mode = 0;
else if (type_str->s() == "eval")
......@@ -502,10 +503,12 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
else {
raiseExcHelper(ValueError, "compile() arg 3 must be 'exec', 'eval' or 'single'");
}
if (only_ast) // nothing to do
return source;
mod = PyAST_obj2mod(source, arena, mode);
if (PyErr_Occurred())
throwCAPIException();
parsed = cpythonToPystonAST(mod, filename_str->c_str());
} else {
RELEASE_ASSERT(PyString_Check(source), "");
int mode;
......@@ -521,15 +524,12 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
PyCompilerFlags cf;
cf.cf_flags = future_flags;
ArenaWrapper arena;
const char* code = static_cast<BoxedString*>(source)->s().data();
assert(arena);
const char* fn = filename_str->c_str();
mod = PyParser_ASTFromString(code, fn, mode, &cf, arena);
if (!mod)
throwCAPIException();
parsed = cpythonToPystonAST(mod, filename_str->c_str());
}
if (only_ast) {
......@@ -540,6 +540,10 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
return result;
}
// be careful when moving around this function: it does also do some additional syntax checking (=raises exception),
// which we should not do when in AST only mode.
parsed = cpythonToPystonAST(mod, filename_str->c_str());
PyCompilerFlags pcf;
pcf.cf_flags = future_flags;
......
......@@ -24,7 +24,6 @@ test_al No module named al
test_applesingle Not really a failure, but it tries to skip itself and we don't support that
test_argparse [unknown]
test_ascii_formatd segfault in ctypes (but only on CI)
test_ast mismatch of parser error checks. remove test/tests/test_ast.py when the orig test passes
test_asynchat [unknown]
test_asyncore [unknown]
test_atexit [unknown]
......
test_AST_objects (__main__.AST_Tests) ... ok
test_arguments (__main__.AST_Tests) ... ok
test_base_classes (__main__.AST_Tests) ... ok
test_classattrs (__main__.AST_Tests) ... ok
test_field_attr_existence (__main__.AST_Tests) ... ok
test_field_attr_writable (__main__.AST_Tests) ... ok
test_from_import (__main__.AST_Tests) ... ok
test_invalid_identitifer (__main__.AST_Tests) ... ok
test_invalid_string (__main__.AST_Tests) ... ok
test_module (__main__.AST_Tests) ... ok
test_no_fields (__main__.AST_Tests) ... ok
test_nodeclasses (__main__.AST_Tests) ... ok
test_non_interned_future_from_ast (__main__.AST_Tests) ... ok
test_pickling (__main__.AST_Tests) ... skipped 'parse error'
test_slice (__main__.AST_Tests) ... ok
test_snippets (__main__.AST_Tests) ... skipped 'parse error'
test_copy_location (__main__.ASTHelpers_Test) ... ok
test_dump (__main__.ASTHelpers_Test) ... ok
test_fix_missing_locations (__main__.ASTHelpers_Test) ... ok
test_get_docstring (__main__.ASTHelpers_Test) ... ok
test_increment_lineno (__main__.ASTHelpers_Test) ... ok
test_iter_child_nodes (__main__.ASTHelpers_Test) ... ok
test_iter_fields (__main__.ASTHelpers_Test) ... ok
test_literal_eval (__main__.ASTHelpers_Test) ... ok
test_literal_eval_issue4907 (__main__.ASTHelpers_Test) ... ok
test_parse (__main__.ASTHelpers_Test) ... ok
----------------------------------------------------------------------
Ran 26 tests in TIME
OK (skipped=2)
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment