mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-24 13:34:52 +00:00
Fix global declaration error in the function
Fix Global symbol to prevent syntax error when global declaration for same variable in function. Fixes #1353
This commit is contained in:
parent
bff58fd626
commit
18c243854e
1 changed files with 11 additions and 4 deletions
|
@ -746,10 +746,15 @@ impl SymbolTableBuilder {
|
|||
// Role already set..
|
||||
match role {
|
||||
SymbolUsage::Global => {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("name '{}' is used prior to global declaration", name),
|
||||
location,
|
||||
})
|
||||
let symbol = table.symbols.get(name).unwrap();
|
||||
if let SymbolScope::Global = symbol.scope {
|
||||
// Ok
|
||||
} else {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("name '{}' is used prior to global declaration", name),
|
||||
location,
|
||||
});
|
||||
}
|
||||
}
|
||||
SymbolUsage::Nonlocal => {
|
||||
return Err(SymbolTableError {
|
||||
|
@ -806,6 +811,8 @@ impl SymbolTableBuilder {
|
|||
SymbolUsage::Global => {
|
||||
if let SymbolScope::Unknown = symbol.scope {
|
||||
symbol.scope = SymbolScope::Global;
|
||||
} else if let SymbolScope::Global = symbol.scope {
|
||||
// Global scope can be set to global
|
||||
} else {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("Symbol {} scope cannot be set to global, since its scope was already determined otherwise.", name),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue