fix: super class can be an expression

This commit is contained in:
BLUELOVETH 2023-07-07 18:15:58 +08:00
parent 8197e35948
commit b520abf7a2
2 changed files with 11 additions and 7 deletions

View File

@ -830,15 +830,19 @@ __SUBSCR_END:
void Compiler::compile_class(){ void Compiler::compile_class(){
consume(TK("@id")); consume(TK("@id"));
int namei = StrName(prev().str()).index; int namei = StrName(prev().str()).index;
int super_namei = -1; Expr_ base = nullptr;
if(match(TK("("))){ if(match(TK("("))){
if(match(TK("@id"))){ if(is_expression()){
super_namei = StrName(prev().str()).index; EXPR();
base = ctx()->s_expr.popx();
} }
consume(TK(")")); consume(TK(")"));
} }
if(super_namei == -1) ctx()->emit(OP_LOAD_NONE, BC_NOARG, prev().line); if(base == nullptr){
else ctx()->emit(OP_LOAD_GLOBAL, super_namei, prev().line); ctx()->emit(OP_LOAD_NONE, BC_NOARG, prev().line);
}else {
base->emit(ctx());
}
ctx()->emit(OP_BEGIN_CLASS, namei, BC_KEEPLINE); ctx()->emit(OP_BEGIN_CLASS, namei, BC_KEEPLINE);
ctx()->is_compiling_class = true; ctx()->is_compiling_class = true;
compile_block_body(); compile_block_body();

View File

@ -92,9 +92,9 @@ class B(A):
assert B.b == 3 assert B.b == 3
assert B.c == 4 assert B.c == 4
from c import void_p import c
class A(void_p): class A(c.void_p):
pass pass
a = A() a = A()