blueloveTH 2 лет назад
Родитель
Сommit
0caa14172d
2 измененных файлов с 13 добавлено и 1 удалено
  1. 4 1
      src/compiler.cpp
  2. 9 0
      tests/99_bugs.py

+ 4 - 1
src/compiler.cpp

@@ -775,7 +775,10 @@ __EAT_DOTS_END:
             case TK("++"):{
                 consume(TK("@id"));
                 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:
                         ctx()->emit(OP_INC_FAST, ctx()->add_varname(name), prev().line);
                         break;

+ 9 - 0
tests/99_bugs.py

@@ -70,3 +70,12 @@ try:
     exit(1)
 except UnboundLocalError:
     pass
+
+
+g = 1
+def f():
+    global g
+    ++g
+
+f(); f()
+assert g == 3