-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore Array.deep from ArrayLike #6912
Conversation
|
||
/** Creates a possible nested `IndexedSeq` which consists of all the elements | ||
* of this array. If the elements are arrays themselves, the `deep` transformation | ||
* is applied recursively to them. The `stringPrefix` of the `IndexedSeq` is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be className
instead of stringPrefix
case x: Array[Boolean] => deep((new mutable.ArraySeq.ofBoolean(x) ).asInstanceOf[mutable.ArraySeq[Boolean]]) | ||
case x: Array[Unit] => deep((new mutable.ArraySeq.ofUnit(x) ).asInstanceOf[mutable.ArraySeq[Unit]] ) | ||
case x => x | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation in 2.12.x seems simpler: https://github.com/scala/scala/blob/2.12.x/src/library/scala/collection/mutable/ArrayLike.scala#L41-L44
Is there a reason to have all these case
s?
Can you also fix the commit message? |
c92030f
to
f5490b4
Compare
f5490b4
to
8ae7713
Compare
@julienrf done, ci is ✔️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we go one step further and remove this prettyArray
thing from partest Utils
. This will have the nice side effect of decreasing the number of blacklisted partests in Scala.js.
implicit class ArrayDeep(val a: Array[_]) extends AnyVal { | ||
def deep: collection.IndexedSeq[Any] = prettyArray(a) | ||
def prettyArray: collection.IndexedSeq[Any] = prettyArray0(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I’m thinking about something: the less code we have in this file, the more compatible with Scala.js partests are. Currently, all the tests that use the deep
method that you renamed to prettyArray
are blacklisted in Scala.js because this Util.scala
file is not used by Scala.js, therefore the partests that use features defined in that file don’t compile.
Maybe it’s an opportunity to remove this prettyArray
thing at all. Do we really need a method that wraps arbitrarily nested levels of Arrays
to IndexedSeq
s? I guess we usually have one or two levels of nested arrays, so the fix consists in manually calling .toSeq
or .map(_.toSeq).toSeq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we keep Array.deep
without deprecation. This method is useful to print an array or check for equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure. To print an array I find it simple to call .toSeq
. To check for equality we can use Java’s Arrays.deepEquals
. What do other people think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array(Array(1)).toSeq.toString // WrappedArray([I@6fc1a8f6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep it, deep
is certainly a not a good name. Are there any other use cases than toString
? If not, there should instead be a method that returns the string representation directly.
Personally, I think the method is not widely useful enough for the standard libarary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for pretty-printing and checking for equality in tests. If you use Arrays.deepEquals, you only have one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The very fact that deep()
returns an IndexedSeq[Any]
is a huge smell. It's basically not type parametric. If I manipulate an Array[T]
and I call deep()
on it, I am at the mercy of some of the T
s being Array
s. It's the same huge problem that JavaScript Promise
s face.
Kill it.
@@ -108,7 +108,7 @@ object Test4 { | |||
import java.lang.reflect.AnnotatedElement | |||
def printSourceAnnotation(a: Annotation): Unit = { | |||
val ann = a.asInstanceOf[SourceAnnotation] | |||
println("@test.SourceAnnotation(mails=" + ann.mails.deep.mkString("{", ",", "}") + | |||
println("@test.SourceAnnotation(mails=" + ann.mails.prettyArray.mkString("{", ",", "}") + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, here we can just remove deep
: ann.mails.mkString("{", ",", "}")
@@ -71,7 +71,7 @@ object Test2 { | |||
println() | |||
|
|||
def loadArray[T](x: Array[Byte])(implicit t: reflect.ClassTag[Array[T]]) = | |||
load[Array[T]](x)(t).deep.toString | |||
load[Array[T]](x)(t).prettyArray.toString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can replace deep
with toSeq
.
@@ -71,7 +71,7 @@ object Test2 { | |||
println() | |||
|
|||
def loadArray[T](x: Array[Byte])(implicit m: reflect.Manifest[Array[T]]) = | |||
load[Array[T]](x)(m).deep.toString | |||
load[Array[T]](x)(m).prettyArray.toString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace deep
with toSeq
Why did you close the PR? |
@julienrf It looks like no one is on board with the idea of keeping this method. We should add this in |
I don’t think we should add it to scala-collection-compat (see my comment there). But we can simply not use it and manually migrate the projects that used to rely on it (like our partests) |
fix scala/bug#10985