Skip to content

Commit 8dfd2ba

Browse files
committed
Fix error handling in next builtin
1 parent 934230d commit 8dfd2ba

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,28 +1436,31 @@ public abstract static class MinNode extends MinMaxNode {
14361436
public abstract static class NextNode extends PythonBinaryBuiltinNode {
14371437
@Specialization(guards = "isNoValue(defaultObject)")
14381438
public Object next(VirtualFrame frame, Object iterator, PNone defaultObject,
1439-
@Cached("create()") GetNextNode next,
1440-
@Cached("create()") IsBuiltinClassProfile errorProfile) {
1441-
try {
1442-
return next.execute(frame, iterator);
1443-
} catch (PException e) {
1444-
e.expectAttributeError(errorProfile);
1445-
throw raise(TypeError, e.setCatchingFrameAndGetEscapedException(frame), ErrorMessages.OBJ_ISNT_ITERATOR, iterator);
1446-
}
1439+
@Cached("createNextCall()") LookupAndCallUnaryNode callNode) {
1440+
return callNode.executeObject(frame, iterator);
14471441
}
14481442

14491443
@Specialization(guards = "!isNoValue(defaultObject)")
14501444
public Object next(VirtualFrame frame, Object iterator, Object defaultObject,
1451-
@Cached("create()") NextNode next,
1445+
@Cached("createNextCall()") LookupAndCallUnaryNode callNode,
14521446
@Cached("create()") IsBuiltinClassProfile errorProfile) {
14531447
try {
1454-
return next.execute(frame, iterator, PNone.NO_VALUE);
1448+
return callNode.executeObject(frame, iterator);
14551449
} catch (PException e) {
14561450
e.expectStopIteration(errorProfile);
14571451
return defaultObject;
14581452
}
14591453
}
14601454

1455+
protected LookupAndCallUnaryNode createNextCall() {
1456+
return LookupAndCallUnaryNode.create(__NEXT__, () -> new LookupAndCallUnaryNode.NoAttributeHandler() {
1457+
@Override
1458+
public Object execute(Object iterator) {
1459+
throw raise(TypeError, ErrorMessages.OBJ_ISNT_ITERATOR, iterator);
1460+
}
1461+
});
1462+
}
1463+
14611464
protected static NextNode create() {
14621465
return BuiltinFunctionsFactory.NextNodeFactory.create();
14631466
}

0 commit comments

Comments
 (0)