blueloveTH 2025-07-03 18:11:35 +08:00
parent d5a511ad7c
commit ccd00e83a5
2 changed files with 9 additions and 2 deletions

View File

@ -2865,13 +2865,14 @@ static Error* compile_stmt(Compiler* self) {
bool is_typed_name = false; // e.g. x: int
// eat variable's type hint if it is a single name
if(Ctx__s_top(ctx())->vt->is_name) {
const ExprVt* top_vt = Ctx__s_top(ctx())->vt;
if(top_vt->is_name || top_vt->is_attrib) {
if(match(TK_COLON)) {
c11_sv type_hint;
check(consume_type_hints_sv(self, &type_hint));
is_typed_name = true;
if(ctx()->is_compiling_class) {
if(ctx()->is_compiling_class && top_vt->is_name) {
NameExpr* ne = (NameExpr*)Ctx__s_top(ctx());
int index = Ctx__add_const_string(ctx(), type_hint);
Ctx__emit_(ctx(), OP_LOAD_CONST, index, BC_KEEPLINE);

View File

@ -126,7 +126,13 @@ class MyClass:
b, c = 1, 2
d = b + c
def __init__(self, m, n) -> None:
self.m: int = m
self.n: float = n
assert MyClass.a == (1, 2, 3)
assert MyClass.b == 1
assert MyClass.c == 2
assert MyClass.d == 3
assert MyClass(1, 2).m == 1