mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
fix a bug of with
This commit is contained in:
parent
b13581037d
commit
fc2a80122b
@ -839,12 +839,13 @@ __SUBSCR_END:
|
|||||||
EXPR(false);
|
EXPR(false);
|
||||||
consume(TK("as"));
|
consume(TK("as"));
|
||||||
consume(TK("@id"));
|
consume(TK("@id"));
|
||||||
StrName name(prev().str());
|
Expr_ e = make_expr<NameExpr>(prev().str(), name_scope());
|
||||||
ctx()->emit(OP_STORE_NAME, name.index, prev().line);
|
bool ok = e->emit_store(ctx());
|
||||||
ctx()->emit(OP_LOAD_NAME, name.index, prev().line);
|
if(!ok) SyntaxError();
|
||||||
|
e->emit(ctx());
|
||||||
ctx()->emit(OP_WITH_ENTER, BC_NOARG, prev().line);
|
ctx()->emit(OP_WITH_ENTER, BC_NOARG, prev().line);
|
||||||
compile_block_body();
|
compile_block_body();
|
||||||
ctx()->emit(OP_LOAD_NAME, name.index, prev().line);
|
e->emit(ctx());
|
||||||
ctx()->emit(OP_WITH_EXIT, BC_NOARG, prev().line);
|
ctx()->emit(OP_WITH_EXIT, BC_NOARG, prev().line);
|
||||||
} break;
|
} break;
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
|
@ -27,11 +27,14 @@ with open('123.bin', 'wb') as f:
|
|||||||
f.write('123'.encode())
|
f.write('123'.encode())
|
||||||
f.write('测试'.encode())
|
f.write('测试'.encode())
|
||||||
|
|
||||||
|
def f():
|
||||||
with open('123.bin', 'rb') as f:
|
with open('123.bin', 'rb') as f:
|
||||||
b = f.read()
|
b = f.read()
|
||||||
assert isinstance(b, bytes)
|
assert isinstance(b, bytes)
|
||||||
assert b == '123测试'.encode()
|
assert b == '123测试'.encode()
|
||||||
|
|
||||||
|
f()
|
||||||
|
|
||||||
assert os.path.exists('123.bin')
|
assert os.path.exists('123.bin')
|
||||||
os.remove('123.bin')
|
os.remove('123.bin')
|
||||||
assert not os.path.exists('123.bin')
|
assert not os.path.exists('123.bin')
|
Loading…
x
Reference in New Issue
Block a user