Skip to content

Commit a92fc77

Browse files
committed
fix varargs
1 parent 62d7e66 commit a92fc77

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/codegen/src/compile.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,15 @@ impl Compiler {
741741
}
742742
0 => {
743743
// 0-arg: super() - need __class__ cell and first parameter
744-
// Check if we're in a function with at least one parameter
744+
// Check if we're in a function with at least one *positional* argument
745+
// (or *args which becomes varnames[0] when no positional args exist).
746+
// A function may have varnames (locals) but no positional args, e.g.:
747+
// def inner(): x = 1; return super().foo
748+
// In this case, optimization should not apply.
745749
let info = self.code_stack.last()?;
746-
if info.metadata.varnames.is_empty() {
750+
let has_first_arg = info.metadata.argcount > 0
751+
|| info.flags.contains(bytecode::CodeFlags::VARARGS);
752+
if !has_first_arg {
747753
return None;
748754
}
749755

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
Arg, BinaryOperator, BorrowedConstant, BuildSliceArgCount, ComparisonOperator, Constant,
77
ConvertValueOparg, InstrDisplayContext, IntrinsicFunction1, IntrinsicFunction2, Invert,
88
Label, MakeFunctionFlags, NameIdx, OpArg, RaiseKind, UnpackExArgs, decode_load_attr_arg,
9+
decode_load_super_attr_arg,
910
},
1011
marshal::MarshalError,
1112
};

0 commit comments

Comments
 (0)