Visitar URL original
Refactor compile_function by youknowone · Pull Request #6001 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix scope error
  • Loading branch information
youknowone committed Jul 19, 2025
commit 957f4de49098150243c199a02f42ec52496fb052
13 changes: 12 additions & 1 deletion compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,18 @@ impl Compiler<'_> {
// compiler_exit_scope
fn exit_scope(&mut self) -> CodeObject {
let table = self.pop_symbol_table();
assert!(table.sub_tables.is_empty());

// TypeParams scope can have sub_tables (the function body's symbol table)
// This matches CPython's behavior where type params scope contains the function scope
if table.typ != CompilerScope::TypeParams {
assert!(
table.sub_tables.is_empty(),
"Only TypeParams scope can have sub_tables, but {:?} has {} sub_tables",
table.typ,
table.sub_tables.len()
);
}

let pop = self.code_stack.pop();
let stack_top = compiler_unwrap_option(self, pop);
unwrap_internal(self, stack_top.finalize_code(self.opts.optimize))
Expand Down