mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-04 01:21:27 +00:00
Fix scope error
This commit is contained in:
parent
a6be7eea26
commit
f6eb1168bc
2 changed files with 9 additions and 3 deletions
|
@ -298,7 +298,15 @@ impl<O: OutputStream> Compiler<O> {
|
|||
SymbolScope::Global => bytecode::NameScope::Global,
|
||||
SymbolScope::Nonlocal => bytecode::NameScope::NonLocal,
|
||||
SymbolScope::Unknown => bytecode::NameScope::Free,
|
||||
SymbolScope::Local => bytecode::NameScope::Local,
|
||||
SymbolScope::Local => {
|
||||
// Only in function block, we use load local
|
||||
// https://github.com/python/cpython/blob/master/Python/compile.c#L3582
|
||||
if self.ctx.in_func() {
|
||||
bytecode::NameScope::Local
|
||||
} else {
|
||||
bytecode::NameScope::Free
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -281,8 +281,6 @@ impl<'a> SymbolTableAnalyzer<'a> {
|
|||
fn analyze_unknown_symbol(&self, symbol: &mut Symbol) {
|
||||
if symbol.is_assigned || symbol.is_parameter {
|
||||
symbol.scope = SymbolScope::Local;
|
||||
} else if symbol.is_referenced {
|
||||
symbol.scope = SymbolScope::Unknown;
|
||||
} else {
|
||||
// Interesting stuff about the __class__ variable:
|
||||
// https://docs.python.org/3/reference/datamodel.html?highlight=__class__#creating-the-class-object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue