mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix scope_for_name to catch NameError properly
This commit is contained in:
@@ -1877,7 +1877,9 @@ impl<O: OutputStream> Compiler<O> {
|
||||
fn lookup_name(&self, name: &str) -> &Symbol {
|
||||
// println!("Looking up {:?}", name);
|
||||
let scope = self.scope_stack.last().unwrap();
|
||||
scope.lookup(name).unwrap()
|
||||
scope.lookup(name).expect(
|
||||
"The symbol must be present in the symbol table, even when it is undefined in python.",
|
||||
)
|
||||
}
|
||||
|
||||
// Low level helper functions:
|
||||
|
||||
@@ -244,13 +244,11 @@ impl SymbolTableBuilder {
|
||||
} => {
|
||||
self.scan_expressions(decorator_list)?;
|
||||
self.register_name(name, SymbolRole::Assigned)?;
|
||||
|
||||
self.enter_function(args)?;
|
||||
|
||||
self.scan_statements(body)?;
|
||||
if let Some(expression) = returns {
|
||||
self.scan_expression(expression)?;
|
||||
}
|
||||
self.enter_function(args)?;
|
||||
self.scan_statements(body)?;
|
||||
self.leave_scope();
|
||||
}
|
||||
ClassDef {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
__name__ = "function"
|
||||
|
||||
|
||||
@@ -72,3 +71,20 @@ def f6():
|
||||
|
||||
|
||||
f6()
|
||||
|
||||
|
||||
def f7():
|
||||
try:
|
||||
def t() -> void: # noqa: F821
|
||||
pass
|
||||
except NameError:
|
||||
return True
|
||||
return False
|
||||
|
||||
assert f7()
|
||||
|
||||
|
||||
def f8() -> int:
|
||||
return 10
|
||||
|
||||
assert f8() == 10
|
||||
|
||||
Reference in New Issue
Block a user