Merge pull request #2903 from Snowapril/fix-syntax-test

Add syntax error detection routine for global symbol
This commit is contained in:
Jeong YunWon
2021-08-18 01:27:44 +09:00
committed by GitHub
2 changed files with 30 additions and 6 deletions

View File

@@ -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):

View File

@@ -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 => {