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
Use method mode for function-local import attribute calls
Function-local imports (scope is Local+IMPORTED) should use method
mode LOAD_ATTR like regular names, not plain mode. Only module/class
scope imports use plain LOAD_ATTR + PUSH_NULL.
  • Loading branch information
youknowone committed Mar 25, 2026
commit 122f76a176855530459a79c0ad6e5e00ab260ecd
16 changes: 13 additions & 3 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,23 @@ impl Compiler {

/// Check if a name is imported in current scope or any enclosing scope.
fn is_name_imported(&self, name: &str) -> bool {
if let Some(sym) = self.current_symbol_table().symbols.get(name) {
let current = self.current_symbol_table();
if let Some(sym) = current.symbols.get(name) {
if sym.flags.contains(SymbolFlags::IMPORTED) {
return true;
} else if sym.scope == SymbolScope::Local {
// Module/class scope imports use plain LOAD_ATTR
// Function-local imports use method mode (scope is Local)
return !matches!(
current.typ,
CompilerScope::Function
| CompilerScope::AsyncFunction
| CompilerScope::Lambda
);
}
if sym.scope == SymbolScope::Local {
return false;
}
}
// Check enclosing scopes for module-level imports accessed as globals
self.symbol_table_stack.iter().rev().skip(1).any(|table| {
table
.symbols
Expand Down