Compare commits

..

5 Commits

Author SHA1 Message Date
killcerr
a51d7bba02
Merge 5ab8381471d55d3e966db4987942ec34665b44fa into 2fa14c588463bf576bce766f6ae996e7e8e10271 2026-01-30 16:41:15 +00:00
killcerr
5ab8381471 fix #440 2026-01-31 00:41:20 +08:00
killcerr
a92557193c fix #440 2026-01-30 23:15:39 +08:00
killcerr
1b2ad4cf2a fix #440 2026-01-30 22:08:34 +08:00
killcerr
7b733cae0a fix #440 2026-01-30 21:16:49 +08:00
2 changed files with 31 additions and 5 deletions

View File

@ -1143,20 +1143,33 @@ __NEXT_STEP:
}
case OP_EXCEPTION_MATCH: {
bool ok = false;
bool has_invalid = false;
if(TOP()->type == tp_type) {
ok = py_isinstance(&self->unhandled_exc, py_totype(TOP()));
} else if(TOP()->type == tp_tuple) {
int len = py_tuple_len(TOP());
py_ObjectRef data = py_tuple_data(TOP());
for(int i = 0; i < len; i++) {
if(!py_checktype(data + i, tp_type)) goto __ERROR;
if(py_isinstance(&self->unhandled_exc, py_totype(data + i))) {
ok = true;
if((data + i)->type != tp_type) {
has_invalid = true;
break;
}
}
} else
goto __ERROR;
if(!has_invalid) {
for(int i = 0; i < len; i++) {
if(py_isinstance(&self->unhandled_exc, py_totype(data + i))) {
ok = true;
break;
}
}
}
} else {
has_invalid = true;
}
if(has_invalid) {
py_clearexc(NULL);
TypeError("catching classes that do not inherit from BaseException is not allowed");
}
py_newbool(TOP(), ok);
DISPATCH();
}

View File

@ -201,6 +201,19 @@ for i in range(6):
a.append(i)
assert a == [0, 1, 3, 4, 5]
try:
result = 10 / 0
except (ZeroDivisionError, TypeError) as e:
assert type(e) == ZeroDivisionError
try:
try:
result = 10 / 0
except (ZeroDivisionError, 1) as e:
assert type(e) == ZeroDivisionError
except Exception as e:
assert type(e) == TypeError
"""
# finally, only
def finally_only():