Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,17 @@ impl Compiler {
self.check_forbidden_name(&name, usage)?;

let symbol_table = self.symbol_table_stack.last().unwrap();
let symbol = symbol_table.lookup(name.as_ref()).unwrap_or_else(||
panic!("The symbol '{name}' must be present in the symbol table, even when it is undefined in python."),
);
let symbol = match symbol_table.lookup(name.as_ref()) {
Some(s) => s,
None => {
return Err(self.error_loc(
CodegenErrorType::SymbolLookupError {
symbol: name.to_string(),
},
self.current_source_location,
));
}
};
let info = self.code_stack.last_mut().unwrap();
let mut cache = &mut info.name_cache;
enum NameOpType {
Expand Down
4 changes: 4 additions & 0 deletions compiler/codegen/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum CodegenErrorType {
DuplicateStore(String),
InvalidMatchCase,
NotImplementedYet, // RustPython marker for unimplemented features
SymbolLookupError { symbol: String },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is not a user-side Python error but our own RustPython implementation bug, let's not expose it here.

}

impl std::error::Error for CodegenErrorType {}
Expand Down Expand Up @@ -85,6 +86,9 @@ impl fmt::Display for CodegenErrorType {
}
NotImplementedYet => {
write!(f, "RustPython does not implement this feature yet")
},
SymbolLookupError { symbol } => {
write!(f, "The symbol {symbol} must be present in the symbol table, even when it is undefined in python")
}
}
}
Expand Down
Loading