8000 Merge pull request #2670 from jepler/compile-assertion-errors · gregdavill/circuitpython@2e37000 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e37000

Browse files
authored
Merge pull request adafruit#2670 from jepler/compile-assertion-errors
Turn certain assertion errors in mpy-cross into SyntaxErrors
2 parents 29e4472 + 402262a commit 2e37000

15 files changed

+2815
-26
lines changed

locale/ID.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/circuitpython.pot

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/de_DE.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/en_US.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/en_x_pirate.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/es.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/fil.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/fr.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/it_IT.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/ko.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/pl.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/pt_BR.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

locale/zh_Latn_pinyin.po

Lines changed: 215 additions & 2 deletions
Large diffs are not rendered by default.

py/compile.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,16 @@ STATIC void compile_yield_from(compiler_t *comp) {
17111711
}
17121712

17131713
#if MICROPY_PY_ASYNC_AWAIT
1714+
STATIC bool compile_require_async_context(compiler_t *comp, mp_parse_node_struct_t *pns) {
1715+
int scope_flags = comp->scope_cur->scope_flags;
1716+
if(scope_flags & MP_SCOPE_FLAG_GENERATOR) {
1717+
return true;
1718+
}
1719+
compile_syntax_error(comp, (mp_parse_node_t)pns,
1720+
translate("'async for' or 'async with' outside async function"));
1721+
return false;
1722+
}
1723+
17141724
STATIC void compile_await_object_method(compiler_t *comp, qstr method) {
17151725
EMIT_ARG(load_method, method, false);
17161726
EMIT_ARG(call_method, 0, 0, 0);
@@ -1720,6 +1730,10 @@ STATIC void compile_await_object_method(compiler_t *comp, qstr method) {
17201730
STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
17211731
// comp->break_label |= MP_EMIT_BREAK_FROM_FOR;
17221732

1733+
if(!compile_require_async_context(comp, pns)) {
1734+
return;
1735+
}
1736+
17231737
qstr context = MP_PARSE_NODE_LEAF_ARG(pns->nodes[1]);
17241738
uint while_else_label = comp_next_label(comp);
17251739
uint try_exception_label = comp_next_label(comp);
@@ -1857,6 +1871,9 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, int n, mp_parse_nod
18571871
}
18581872

18591873
STATIC void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
1874+
if(!compile_require_async_context(comp, pns)) {
1875+
return;
1876+
}
18601877
// get the nodes for the pre-bit of the with (the a as b, c as d, ... bit)
18611878
mp_parse_node_t *nodes;
18621879
int n = mp_parse_node_extract_list(&pns->nodes[0], PN_with_stmt_list, &nodes);

py/parse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) {
477477
mp_parse_node_t pn;
478478
mp_lexer_t *lex = parser->lexer;
479479
if (lex->tok_kind == MP_TOKEN_NAME) {
480+
if(lex->vstr.len >= (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN))) {
481+
mp_raise_msg(&mp_type_SyntaxError, translate("Name too long"));
482+
}
480483
qstr id = qstr_from_strn(lex->vstr.buf, lex->vstr.len);
481484
#if MICROPY_COMP_CONST
482485
// if name is a standalone identifier, look it up in the table of dynamic constants

0 commit comments

Comments
 (0)
0