Skip to content

Commit 804760b

Browse files
committed
py: Fix bug in compiler for empty class bases.
Eg class A(): pass would fail an assertion.
1 parent 0997af9 commit 804760b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

py/compile.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,13 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
955955
EMIT_ARG(load_const_id, cscope->simple_name);
956956

957957
// nodes[1] has parent classes, if any
958+
// empty parenthesis (eg class C():) gets here as an empty PN_classdef_2 and needs special handling
959+
mp_parse_node_t parents = pns->nodes[1];
960+
if (MP_PARSE_NODE_IS_STRUCT_KIND(parents, PN_classdef_2)) {
961+
parents = MP_PARSE_NODE_NULL;
962+
}
958963
comp->func_arg_is_super = false;
959-
compile_trailer_paren_helper(comp, pns->nodes[1], false, 2);
964+
compile_trailer_paren_helper(comp, parents, false, 2);
960965

961966
// return its name (the 'C' in class C(...):")
962967
return cscope->simple_name;

0 commit comments

Comments
 (0)