mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix ++
for global
names
This commit is contained in:
parent
e26f389182
commit
0caa14172d
@ -775,7 +775,10 @@ __EAT_DOTS_END:
|
|||||||
case TK("++"):{
|
case TK("++"):{
|
||||||
consume(TK("@id"));
|
consume(TK("@id"));
|
||||||
StrName name(prev().sv());
|
StrName name(prev().sv());
|
||||||
switch(name_scope()){
|
NameScope scope = name_scope();
|
||||||
|
bool is_global = ctx()->global_names.count(name.sv());
|
||||||
|
if(is_global) scope = NAME_GLOBAL;
|
||||||
|
switch(scope){
|
||||||
case NAME_LOCAL:
|
case NAME_LOCAL:
|
||||||
ctx()->emit(OP_INC_FAST, ctx()->add_varname(name), prev().line);
|
ctx()->emit(OP_INC_FAST, ctx()->add_varname(name), prev().line);
|
||||||
break;
|
break;
|
||||||
|
@ -70,3 +70,12 @@ try:
|
|||||||
exit(1)
|
exit(1)
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
g = 1
|
||||||
|
def f():
|
||||||
|
global g
|
||||||
|
++g
|
||||||
|
|
||||||
|
f(); f()
|
||||||
|
assert g == 3
|
Loading…
x
Reference in New Issue
Block a user