Fix scope_for_name to catch NameError properly

This commit is contained in:
Dong-hee Na committed 2019-08-12 10:19:31 +09:00
1 parent 0129bb5c75
commit 6df3800055
3 files changed
+22 -6

No files matched your search

+3 -1
View File
@@ -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:
+2 -4
View File
@@ -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 {
+17 -1
View File
@@ -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