@@ -221,16 +221,10 @@ def handle_aug_assign(func, compilation_context, builder, stmt, local_sym_tab):
221221 f"cannot assign to '{ name } ': it is the context parameter"
222222 )
223223 elif name in compilation_context .bpf_globals :
224- # Binding x anywhere in the body makes it local throughout, so this
225- # statement reads an unbound local rather than the global. Python
226- # raises UnboundLocalError; there is no runtime here in which to do
227- # that, so the program is rejected.
224+ # `x += v` binds x as a local and reads it unbound: UnboundLocalError.
228225 raise SyntaxError (
229- f"local variable '{ name } ' referenced before assignment: "
230- f"'{ name } += ...' binds '{ name } ' as a local, which shadows the "
231- f"@bpfglobal of the same name, and reads it in the same "
232- f"statement (Python raises UnboundLocalError here). Add "
233- f"'global { name } ' to update the global."
226+ f"local variable '{ name } ' referenced before assignment; "
227+ f"add 'global { name } ' to update the @bpfglobal"
234228 )
235229 else :
236230 raise SyntaxError (f"augmented assignment to undefined variable '{ name } '" )
@@ -404,11 +398,6 @@ def process_stmt(
404398 elif isinstance (stmt , ast .AugAssign ):
405399 handle_aug_assign (func , compilation_context , builder , stmt , local_sym_tab )
406400 elif isinstance (stmt , ast .Global ):
407- # Nothing to emit: `global x` binds a name for the whole function body,
408- # so process_func_body collects every declaration before the first
409- # statement is lowered (and before allocation, which would otherwise
410- # give a declared name a stack slot). The branch exists so that a valid
411- # declaration does not reach the unsupported-statement warning below.
412401 logger .debug (f"global declaration of { ', ' .join (stmt .names )} already bound" )
413402 elif isinstance (stmt , ast .If ):
414403 handle_if (func , compilation_context , builder , stmt , local_sym_tab )
0 commit comments