mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #2903 from Snowapril/fix-syntax-test
Add syntax error detection routine for global symbol
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -1121,10 +1121,36 @@ impl SymbolTableBuilder {
|
||||
match role {
|
||||
SymbolUsage::Global => {
|
||||
if !symbol.is_global() {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("name '{}' is used prior to global declaration", name),
|
||||
location,
|
||||
});
|
||||
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 => {
|
||||
|
||||
Reference in New Issue
Block a user