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:
HyeockJinKim 2019-09-18 01:33:31 +09:00
parent bff58fd626
commit 18c243854e

View file

@ -746,10 +746,15 @@ impl SymbolTableBuilder {
// Role already set.. // Role already set..
match role { match role {
SymbolUsage::Global => { SymbolUsage::Global => {
return Err(SymbolTableError { let symbol = table.symbols.get(name).unwrap();
error: format!("name '{}' is used prior to global declaration", name), if let SymbolScope::Global = symbol.scope {
location, // Ok
}) } else {
return Err(SymbolTableError {
error: format!("name '{}' is used prior to global declaration", name),
location,
});
}
} }
SymbolUsage::Nonlocal => { SymbolUsage::Nonlocal => {
return Err(SymbolTableError { return Err(SymbolTableError {
@ -806,6 +811,8 @@ impl SymbolTableBuilder {
SymbolUsage::Global => { SymbolUsage::Global => {
if let SymbolScope::Unknown = symbol.scope { if let SymbolScope::Unknown = symbol.scope {
symbol.scope = SymbolScope::Global; symbol.scope = SymbolScope::Global;
} else if let SymbolScope::Global = symbol.scope {
// Global scope can be set to global
} else { } else {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("Symbol {} scope cannot be set to global, since its scope was already determined otherwise.", name), error: format!("Symbol {} scope cannot be set to global, since its scope was already determined otherwise.", name),