blueloveTH 2025-05-21 19:33:49 +08:00
parent 29cd6fe59b
commit 340309b5d4
2 changed files with 12 additions and 9 deletions

View File

@ -479,13 +479,7 @@ bool TupleExpr__emit_store(Expr* self_, Ctx* ctx) {
} }
if(starred_i == -1) { if(starred_i == -1) {
Bytecode* prev = c11__at(Bytecode, &ctx->co->codes, ctx->co->codes.length - 1); Ctx__emit_(ctx, OP_UNPACK_SEQUENCE, self->itemCount, self->line);
if(prev->op == OP_BUILD_TUPLE && prev->arg == self->itemCount) {
// build tuple and unpack it is meaningless
Ctx__revert_last_emit_(ctx);
} else {
Ctx__emit_(ctx, OP_UNPACK_SEQUENCE, self->itemCount, self->line);
}
} else { } else {
// starred assignment target must be in a tuple // starred assignment target must be in a tuple
if(self->itemCount == 1) return false; if(self->itemCount == 1) return false;
@ -2177,7 +2171,7 @@ Error* try_compile_assignment(Compiler* self, bool* is_assign) {
} }
case TK_ASSIGN: { case TK_ASSIGN: {
consume(TK_ASSIGN); consume(TK_ASSIGN);
int n = 0; int n = 0; // assignment count
if(match(TK_YIELD_FROM)) { if(match(TK_YIELD_FROM)) {
check(compile_yield_from(self, prev()->line)); check(compile_yield_from(self, prev()->line));

View File

@ -148,4 +148,13 @@ assert A.x == [1, 2, 3]
a = [(0, 1), (1, 1), (1, 2)] a = [(0, 1), (1, 1), (1, 2)]
b = sorted(a, key=lambda x: x[0]) b = sorted(a, key=lambda x: x[0])
if b != [(0, 1), (1, 1), (1, 2)]: if b != [(0, 1), (1, 1), (1, 2)]:
assert False, b assert False, b
# https://github.com/pocketpy/pocketpy/issues/367
a = 10 if False else 5
assert a == 5
a, b, c = (1, 2, 3) if True else (4, 5, 6)
assert a == 1
assert b == 2
assert c == 3