diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index a87ef0f72..7067a6e4d 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -673,8 +673,6 @@ class SyntaxTestCase(unittest.TestCase): def test_assign_del(self): self._check_error("del f()", "delete") - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_global_param_err_first(self): source = """if 1: def error(a): diff --git a/compiler/src/symboltable.rs b/compiler/src/symboltable.rs index 10c13ba55..8dc120e26 100644 --- a/compiler/src/symboltable.rs +++ b/compiler/src/symboltable.rs @@ -1120,12 +1120,33 @@ impl SymbolTableBuilder { // Role already set.. match role { SymbolUsage::Global => { - if !symbol.is_global() { + if symbol.is_parameter { + return Err(SymbolTableError { + error: format!("name '{}' is parameter and global", name), + location, + }); + } + if symbol.is_referenced { return Err(SymbolTableError { error: format!("name '{}' is used prior to global declaration", name), location, }); } + if symbol.is_annotated { + return Err(SymbolTableError { + error: format!("annotated name '{}' can't be global", name), + location, + }); + } + if symbol.is_assigned { + return Err(SymbolTableError { + error: format!( + "name '{}' is assigned to before global declaration", + name + ), + location, + }); + } } SymbolUsage::Nonlocal => { if symbol.is_parameter {