diff --git a/bytecode/src/bytecode.rs b/bytecode/src/bytecode.rs index 871b4efd0..ecb834272 100644 --- a/bytecode/src/bytecode.rs +++ b/bytecode/src/bytecode.rs @@ -53,7 +53,13 @@ bitflags! { const HAS_DEFAULTS = 0x01; const HAS_KW_ONLY_DEFAULTS = 0x02; const HAS_ANNOTATIONS = 0x04; - const NO_NEW_LOCALS = 0x08; + const NEW_LOCALS = 0x08; + } +} + +impl Default for FunctionOpArg { + fn default() -> Self { + Self::NEW_LOCALS } } diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index 838afe31c..3cdcd1876 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -672,7 +672,7 @@ impl Compiler { )); self.enter_scope(); - let mut flags = bytecode::FunctionOpArg::empty(); + let mut flags = bytecode::FunctionOpArg::default(); if have_defaults { flags |= bytecode::FunctionOpArg::HAS_DEFAULTS; } @@ -992,7 +992,7 @@ impl Compiler { // Turn code object into function object: self.emit(Instruction::MakeFunction { - flags: bytecode::FunctionOpArg::NO_NEW_LOCALS, + flags: bytecode::FunctionOpArg::default() & !bytecode::FunctionOpArg::NEW_LOCALS, }); self.emit(Instruction::LoadConst { @@ -1929,7 +1929,7 @@ impl Compiler { // Turn code object into function object: self.emit(Instruction::MakeFunction { - flags: bytecode::FunctionOpArg::empty(), + flags: bytecode::FunctionOpArg::default(), }); // Evaluate iterated item: diff --git a/vm/src/frame.rs b/vm/src/frame.rs index bb02da5ad..3e785fcc7 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -1058,7 +1058,7 @@ impl Frame { scope, defaults, kw_only_defaults, - !flags.contains(bytecode::FunctionOpArg::NO_NEW_LOCALS), + flags.contains(bytecode::FunctionOpArg::NEW_LOCALS), ); let name = qualified_name.as_str().split('.').next_back().unwrap();