Skip to content

Commit 8a2161b

Browse files
committed
fix EG subclass
1 parent 3557eb5 commit 8a2161b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

crates/codegen/src/compile.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,13 +2233,14 @@ impl Compiler {
22332233
emit!(self, Instruction::CheckEgMatch);
22342234
// Stack: [orig, list, new_rest, match]
22352235

2236-
// Check if match is not None
2236+
// Check if match is not None (use identity check, not truthiness)
22372237
// CopyItem is 1-indexed: CopyItem(1) = TOS, CopyItem(2) = second from top
22382238
emit!(self, Instruction::CopyItem { index: 1 });
2239-
emit!(self, Instruction::ToBool);
2239+
self.emit_load_const(ConstantData::None);
2240+
emit!(self, Instruction::IsOp(bytecode::Invert::No)); // is None?
22402241
emit!(
22412242
self,
2242-
Instruction::PopJumpIfFalse {
2243+
Instruction::PopJumpIfTrue {
22432244
target: no_match_block
22442245
}
22452246
);
@@ -2369,9 +2370,10 @@ impl Compiler {
23692370
);
23702371
// Stack: [result] (exception to reraise or None)
23712372

2372-
// CopyItem(1) copies TOS
2373+
// Check if result is not None (use identity check, not truthiness)
23732374
emit!(self, Instruction::CopyItem { index: 1 });
2374-
emit!(self, Instruction::ToBool);
2375+
self.emit_load_const(ConstantData::None);
2376+
emit!(self, Instruction::IsOp(bytecode::Invert::Yes)); // is not None?
23752377
emit!(
23762378
self,
23772379
Instruction::PopJumpIfTrue {

crates/vm/src/exceptions.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,13 @@ pub fn exception_group_match(
25102510
// Check for partial match if it's an exception group
25112511
if exc_value.fast_isinstance(vm.ctx.exceptions.base_exception_group) {
25122512
let pair = vm.call_method(exc_value, "split", (match_type.clone(),))?;
2513+
if !pair.class().is(vm.ctx.types.tuple_type) {
2514+
return Err(vm.new_type_error(format!(
2515+
"{}.split must return a tuple, not {}",
2516+
exc_value.class().name(),
2517+
pair.class().name()
2518+
)));
2519+
}
25132520
let pair_tuple: PyTupleRef = pair.try_into_value(vm)?;
25142521
if pair_tuple.len() < 2 {
25152522
return Err(vm.new_type_error(format!(
@@ -2528,7 +2535,7 @@ pub fn exception_group_match(
25282535
}
25292536

25302537
/// Prepare exception for reraise in except* block.
2531-
/// Implements _PyExc_PrepReraiseStar from Objects/exceptions.c
2538+
/// Implements _PyExc_PrepReraiseStar
25322539
pub fn prep_reraise_star(orig: PyObjectRef, excs: PyObjectRef, vm: &VirtualMachine) -> PyResult {
25332540
use crate::builtins::PyList;
25342541

crates/vm/src/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
33
builtins::{
4-
PyBaseExceptionRef, PyBaseException, PyCode, PyCoroutine, PyDict, PyDictRef, PyGenerator, PyList, PySet,
5-
PySlice, PyStr, PyStrInterned, PyStrRef, PyTraceback, PyType,
4+
PyBaseException, PyBaseExceptionRef, PyCode, PyCoroutine, PyDict, PyDictRef, PyGenerator,
5+
PyList, PySet, PySlice, PyStr, PyStrInterned, PyStrRef, PyTraceback, PyType,
66
asyncgenerator::PyAsyncGenWrappedValue,
77
function::{PyCell, PyCellRef, PyFunction},
88
tuple::{PyTuple, PyTupleRef},

0 commit comments

Comments
 (0)