Przeglądaj źródła

fix https://github.com/pocketpy/pocketpy/issues/367

blueloveTH 9 miesięcy temu
rodzic
commit
340309b5d4
2 zmienionych plików z 12 dodań i 9 usunięć
  1. 2 8
      src/compiler/compiler.c
  2. 10 1
      tests/95_bugs.py

+ 2 - 8
src/compiler/compiler.c

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

+ 10 - 1
tests/95_bugs.py

@@ -148,4 +148,13 @@ assert A.x == [1, 2, 3]
 a = [(0, 1), (1, 1), (1, 2)]
 b = sorted(a, key=lambda x: x[0])
 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