Skip to content

Commit 7736df0

Browse files
committed
Fix scope error
1 parent 6b773f6 commit 7736df0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/codegen/src/compile.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,18 @@ impl Compiler<'_> {
616616
// compiler_exit_scope
617617
fn exit_scope(&mut self) -> CodeObject {
618618
let table = self.pop_symbol_table();
619-
assert!(table.sub_tables.is_empty());
619+
620+
// TypeParams scope can have sub_tables (the function body's symbol table)
621+
// This matches CPython's behavior where type params scope contains the function scope
622+
if table.typ != CompilerScope::TypeParams {
623+
assert!(
624+
table.sub_tables.is_empty(),
625+
"Only TypeParams scope can have sub_tables, but {:?} has {} sub_tables",
626+
table.typ,
627+
table.sub_tables.len()
628+
);
629+
}
630+
620631
let pop = self.code_stack.pop();
621632
let stack_top = compiler_unwrap_option(self, pop);
622633
unwrap_internal(self, stack_top.finalize_code(self.opts.optimize))

0 commit comments

Comments
 (0)