File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -507,9 +507,17 @@ impl Compiler {
507
507
self . check_forbidden_name ( & name, usage) ?;
508
508
509
509
let symbol_table = self . symbol_table_stack . last ( ) . unwrap ( ) ;
510
- let symbol = symbol_table. lookup ( name. as_ref ( ) ) . unwrap_or_else ( ||
511
- panic ! ( "The symbol '{name}' must be present in the symbol table, even when it is undefined in python." ) ,
512
- ) ;
510
+ let symbol = match symbol_table. lookup ( name. as_ref ( ) ) {
511
+ Some ( s) => s,
512
+ None => {
513
+ return Err ( self . error_loc (
514
+ CodegenErrorType :: SymbolLookupError {
515
+ symbol : name. to_string ( ) ,
516
+ } ,
517
+ self . current_source_location ,
518
+ ) ) ;
519
+ }
520
+ } ;
513
521
let info = self . code_stack . last_mut ( ) . unwrap ( ) ;
514
522
let mut cache = & mut info. name_cache ;
515
523
enum NameOpType {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub enum CodegenErrorType {
33
33
DuplicateStore ( String ) ,
34
34
InvalidMatchCase ,
35
35
NotImplementedYet , // RustPython marker for unimplemented features
36
+ SymbolLookupError { symbol : String } ,
36
37
}
37
38
38
39
impl std:: error:: Error for CodegenErrorType { }
@@ -85,6 +86,9 @@ impl fmt::Display for CodegenErrorType {
85
86
}
86
87
NotImplementedYet => {
87
88
write ! ( f, "RustPython does not implement this feature yet" )
89
+ } ,
90
+ SymbolLookupError { symbol } => {
91
+ write ! ( f, "The symbol {symbol} must be present in the symbol table, even when it is undefined in python" )
88
92
}
89
93
}
90
94
}
You can’t perform that action at this time.
0 commit comments