mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
This commit is contained in:
parent
d5a511ad7c
commit
ccd00e83a5
@ -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);
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user