Fix global declaration error in the function
Fix Global symbol to prevent syntax error
when global declaration for same variable in function.
Fixes
@@ -746,10 +746,15 @@ impl SymbolTableBuilder {
// Role already set..
match role {
SymbolUsage::Global => {
+ 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),
