mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30: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);
|
||||
consume(TK("as"));
|
||||
consume(TK("@id"));
|
||||
StrName name(prev().str());
|
||||
ctx()->emit(OP_STORE_NAME, name.index, prev().line);
|
||||
ctx()->emit(OP_LOAD_NAME, name.index, prev().line);
|
||||
Expr_ e = make_expr<NameExpr>(prev().str(), name_scope());
|
||||
bool ok = e->emit_store(ctx());
|
||||
if(!ok) SyntaxError();
|
||||
e->emit(ctx());
|
||||
ctx()->emit(OP_WITH_ENTER, BC_NOARG, prev().line);
|
||||
compile_block_body();
|
||||
ctx()->emit(OP_LOAD_NAME, name.index, prev().line);
|
||||
e->emit(ctx());
|
||||
ctx()->emit(OP_WITH_EXIT, BC_NOARG, prev().line);
|
||||
} break;
|
||||
/*************************************************/
|
||||
|
@ -27,11 +27,14 @@ with open('123.bin', 'wb') as f:
|
||||
f.write('123'.encode())
|
||||
f.write('测试'.encode())
|
||||
|
||||
with open('123.bin', 'rb') as f:
|
||||
def f():
|
||||
with open('123.bin', 'rb') as f:
|
||||
b = f.read()
|
||||
assert isinstance(b, bytes)
|
||||
assert b == '123测试'.encode()
|
||||
|
||||
f()
|
||||
|
||||
assert os.path.exists('123.bin')
|
||||
os.remove('123.bin')
|
||||
assert not os.path.exists('123.bin')
|
Loading…
x
Reference in New Issue
Block a user