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

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

No files matched your search

-2
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):
+30 -4
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 => {