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(){
consume(TK("@id"));
int namei = StrName(prev().str()).index;
int super_namei = -1;
Expr_ base = nullptr;
if(match(TK("("))){
if(match(TK("@id"))){
super_namei = StrName(prev().str()).index;
if(is_expression()){
EXPR();
base = ctx()->s_expr.popx();
}
consume(TK(")"));
}
if(super_namei == -1) ctx()->emit(OP_LOAD_NONE, BC_NOARG, prev().line);
else ctx()->emit(OP_LOAD_GLOBAL, super_namei, prev().line);
if(base == nullptr){
ctx()->emit(OP_LOAD_NONE, BC_NOARG, prev().line);
}else {
base->emit(ctx());
}
ctx()->emit(OP_BEGIN_CLASS, namei, BC_KEEPLINE);
ctx()->is_compiling_class = true;
compile_block_body();

View File

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