mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 02:25:25 +00:00
nonlocal generate syntax error
If the scope depth is less than 2, a syntax error occurs in nonlocal. Fixes #1360
This commit is contained in:
parent
5919a1e1ba
commit
c852c5d272
1 changed files with 2 additions and 1 deletions
|
@ -211,7 +211,8 @@ impl<'a> SymbolTableAnalyzer<'a> {
|
||||||
// symbol.table.borrow().parent.clone();
|
// symbol.table.borrow().parent.clone();
|
||||||
|
|
||||||
if let Some((symbols, _)) = parent_symbol_table {
|
if let Some((symbols, _)) = parent_symbol_table {
|
||||||
if !symbols.contains_key(&symbol.name) {
|
let scope_depth = self.tables.len();
|
||||||
|
if !symbols.contains_key(&symbol.name) || scope_depth < 2 {
|
||||||
return Err(SymbolTableError {
|
return Err(SymbolTableError {
|
||||||
error: format!("no binding for nonlocal '{}' found", symbol.name),
|
error: format!("no binding for nonlocal '{}' found", symbol.name),
|
||||||
location: Default::default(),
|
location: Default::default(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue