Skip to content

Commit cea3f2f

Browse files
committed
support toArray on subclass sets of native types
1 parent 102edfe commit cea3f2f

File tree

1 file changed

+13
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type

1 file changed

+13
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,23 @@ public Iterator<PythonAbstractClass> iterator() {
434434
throw new UnsupportedOperationException();
435435
}
436436

437+
@TruffleBoundary
437438
public Object[] toArray() {
438-
CompilerDirectives.transferToInterpreterAndInvalidate();
439-
throw new UnsupportedOperationException();
439+
Object[] result = new Object[size()];
440+
Iterator<Object> keys = HashingStorageLibrary.getUncached().keys(dict.getDictStorage());
441+
for (int i = 0; i < result.length; i++) {
442+
result[i] = keys.next();
443+
}
444+
return result;
440445
}
441446

447+
@SuppressWarnings("unchecked")
442448
public <T> T[] toArray(T[] a) {
443-
throw new UnsupportedOperationException();
449+
if (a.getClass() == Object[].class) {
450+
return (T[]) toArray();
451+
} else {
452+
throw new UnsupportedOperationException();
453+
}
444454
}
445455

446456
public boolean add(PythonAbstractClass e) {

0 commit comments

Comments
 (0)