Skip to content

Commit 371b0f1

Browse files
committed
Validate super first argument
Fixes #975
1 parent f34d2e0 commit 371b0f1

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

  • graalpython

graalpython/com.oracle.graal.python.test/src/tests/test_super.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def m(self): return ["B"] + self.my_super.m()
4949
assert B().m() == ["B", "A"]
5050

5151

52+
def test_super_requires_type_arg():
53+
try:
54+
super([])
55+
except TypeError:
56+
pass
57+
else:
58+
assert False
59+
60+
5261
def test_super_subclass_descr_get_invokes_subclass_type():
5362
class MySuper(super):
5463
news = []

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ public final Object execute(VirtualFrame frame, Object self, Object[] arguments,
261261
PNone init(VirtualFrame frame, SuperObject self, Object cls, Object obj,
262262
@Bind Node inliningTarget,
263263
@Cached @Exclusive PRaiseNode raiseNode) {
264+
if (!ensureIsTypeNode().executeCached(cls)) {
265+
throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.FIRST_ARGUMENT_MUST_BE_A_TYPE_OBJECT_NOT_P, cls);
266+
}
264267
if (!(obj instanceof PNone)) {
265268
Object type = supercheck(frame, inliningTarget, cls, obj, raiseNode);
266269
self.init(cls, type, obj);

0 commit comments

Comments
 (0)