From b7d8ea63d169951fd43e4b99f373dbc6d53471ad Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sun, 27 Nov 2022 12:47:58 +0100 Subject: [PATCH] Don't use reflection to call Iterable.collectionClassName (#80) This is an issue on GraalVM, where all collection concrete classes would need to be added to some Graal reflection config for collectionClassName to be call-able by reflection. --- pprint/src-2.13/pprint/StringPrefix.scala | 5 +++-- .../scala/collection/internal/pprint/CollectionName.scala | 7 +++++++ pprint/src-3/StringPrefix.scala | 5 ++--- .../scala/collection/internal/pprint/CollectionName.scala | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 pprint/src-2.13/scala/collection/internal/pprint/CollectionName.scala create mode 100644 pprint/src-3/scala/collection/internal/pprint/CollectionName.scala diff --git a/pprint/src-2.13/pprint/StringPrefix.scala b/pprint/src-2.13/pprint/StringPrefix.scala index 76d8f3e..5037068 100644 --- a/pprint/src-2.13/pprint/StringPrefix.scala +++ b/pprint/src-2.13/pprint/StringPrefix.scala @@ -1,5 +1,6 @@ package pprint -object StringPrefix{ - def apply(i: Iterable[_]) = i.asInstanceOf[{ def collectionClassName: String }].collectionClassName +object StringPrefix { + def apply(i: Iterable[_]) = + scala.collection.internal.pprint.CollectionName.get(i) } diff --git a/pprint/src-2.13/scala/collection/internal/pprint/CollectionName.scala b/pprint/src-2.13/scala/collection/internal/pprint/CollectionName.scala new file mode 100644 index 0000000..1743cdb --- /dev/null +++ b/pprint/src-2.13/scala/collection/internal/pprint/CollectionName.scala @@ -0,0 +1,7 @@ +package scala.collection.internal.pprint + +// needs to be in a scala.* package to call Iterable.collectionClassName (which is private[scala]) +object CollectionName { + def get(iterable: scala.collection.Iterable[_]): String = + iterable.collectionClassName +} diff --git a/pprint/src-3/StringPrefix.scala b/pprint/src-3/StringPrefix.scala index f7456b1..64cdfdf 100644 --- a/pprint/src-3/StringPrefix.scala +++ b/pprint/src-3/StringPrefix.scala @@ -1,7 +1,6 @@ package pprint -import reflect.Selectable.reflectiveSelectable - object StringPrefix{ - def apply(i: Iterable[_]) = i.asInstanceOf[{ def collectionClassName: String }].collectionClassName + def apply(i: Iterable[_]) = + scala.collection.internal.pprint.CollectionName.get(i) } diff --git a/pprint/src-3/scala/collection/internal/pprint/CollectionName.scala b/pprint/src-3/scala/collection/internal/pprint/CollectionName.scala new file mode 100644 index 0000000..1743cdb --- /dev/null +++ b/pprint/src-3/scala/collection/internal/pprint/CollectionName.scala @@ -0,0 +1,7 @@ +package scala.collection.internal.pprint + +// needs to be in a scala.* package to call Iterable.collectionClassName (which is private[scala]) +object CollectionName { + def get(iterable: scala.collection.Iterable[_]): String = + iterable.collectionClassName +}