works if each walrus is wrapped in parens

This commit is contained in:
aps 2023-02-15 12:49:27 -05:00
parent 61be706c7d
commit 3bc3114a50
2 changed files with 23 additions and 12 deletions

View File

@ -521,12 +521,12 @@ private:
// in the expression // in the expression
consume(TK(":=")); consume(TK(":="));
emit(OP_LOAD_NAME_REF, index); emit(OP_LOAD_NAME_REF, index);
EXPR(); EXPR_TUPLE();
// emit(OP_LOAD_NAME, index); // emit(OP_LOAD_NAME, index);
emit(OP_STORE_REF); emit(OP_STORE_REF);
emit(OP_LOAD_NAME_REF, index);; emit(OP_LOAD_NAME_REF, index);;
} }
else EXPR(); else EXPR_TUPLE();
} while (match(TK(","))); } while (match(TK(",")));
match_newlines(mode()==REPL_MODE); match_newlines(mode()==REPL_MODE);
consume(TK(")")); consume(TK(")"));

View File

@ -119,13 +119,24 @@ assert round(-23.2) == -23
assert round(-23.8) == -24 assert round(-23.8) == -24
assert (x := 1) == 1 assert (x := 1) == 1
assert (x := 1, y := 2 ) == (1, 2) z = (x := 2)
z = (a := 1, b := 2) assert z == 2
print(z) assert ((a:=1),(b:=2,3)) == (1, (2,3))
assert a == 1 assert a == 1
assert b == 2 assert b == (2,3)
assert (x := (a := 1, b := 2)) == (1, 2) # Note in Python3
assert x == 1 # >>> (x := 1,2,y:=3)
assert (x := 0) + 1 == 1 # (1, 2, 3)
assert (x := 1, y := 2, 3) == (1,2,3) # with x == 1, y == 3
#assert (x := 1, y := 2 ) == (1, 2)
# z = (a := 1, b := 2)
# print(z)
# assert a == 1
# assert b == 2
# assert (x := (a := 1, b := 2)) == (1, 2)
# assert x == 1
# assert (x := 0) + 1 == 1
# assert (x := 1, y := 2, 3) == (1,2,3)