Skip to content
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

Add deprecated toTraversable #6841

Merged
merged 1 commit into from Jun 22, 2018
Merged

Add deprecated toTraversable #6841

merged 1 commit into from Jun 22, 2018

Conversation

ashawley
Copy link
Member

The toTraversable method wasn't deprecated in 2.12, so it needs to be added back to fix clients who had used it in 2.12. It should just be a proxy for toIterable, because Traversable is now just a type alias for Iterable.

After restoring toTraversable back, it needs to be marked deprecated in 2.13, so it can be removed in 2.14.

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone Jun 21, 2018
@ashawley ashawley force-pushed the toTraversable branch 2 times, most recently from c698647 to 97a756a Compare June 21, 2018 21:19
* @return An Iterable containing all elements of this $coll.
*/
@deprecated("Use toIterable instead", "2.13.0")
def toTraversable: Traversable[A]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this abstract? Could we define @deprecated(..) final def toTraversable: Traversable[A] = toIterable here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I was just mimicking the definition of toIterator. I gave it a try and removed the abstract definition. It actually makes this change a lot more minimal.

I don't think there's any reason it needs to be abstract. Actually, it looks like overriding toTraversable was marked deprecated in 3cc99d7. It wasn't possible to actually make it final in 2.12, because it was still being overridden in ParIterableLike and TraversableProxyLike, but we can try to do that here now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second @lrytz, just define it once and implement it at the same time.

The toTraversable method wasn't deprecated in 2.12, so it needs to be
added back to fix clients who had used it in 2.12.  It should just be
a proxy for toIterable, because Traversable is now just a type alias
for Iterable.  After adding toTraversable back, it needs to be marked
deprecated in 2.13, so it can be removed in 2.14.

This method used to be abstract, but there's no reason it still needs
to be going forward.  Overriding toTraversable was marked deprecated
in 3cc99d7.  It should have then been marked final in 2.12, but it
probably wasn't possible since toTraversable was still overridden in
ParIterableLike and TraversableProxyLike.
Copy link
Contributor

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good! We could also add it to StringOps and ArrayOps, for the sake of completeness.

@ashawley
Copy link
Member Author

We could also add it to StringOps and ArrayOps, for the sake of completeness.

Is there some Predef magic with implicits that make the tests I wrote for Array and String misleading?

@julienrf
Copy link
Contributor

Oh I didn’t notice that Array and String were covered by your tests. And indeed since there is an implicit conversion to Seq the toTraversable method is available on Array and String without the need to add them to StringOps and ArrayOps, so we are good!

@lrytz
Copy link
Member

lrytz commented Jun 22, 2018

Thanks @ashawley!

@lrytz lrytz merged commit 94ff57e into scala:2.13.x Jun 22, 2018
@ashawley ashawley deleted the toTraversable branch June 22, 2018 14:41
@ashawley
Copy link
Member Author

I started looking in to whether it would be possible to add toTraversable to ArrayOps and StringOps. It would be possible but it would be difficult since toIterable isn't in scope, yet.

I looked at 2.12, and it doesn't look like toTraversable was defined in ArrayOps or StringOps. So people who may have disabled Predef would not have access toTraversable.

scalacOptions ++= Seq(
  "-Yno-predef",
  "-Yno-imports"
)
import scala.Array
import java.lang.String

// Error: value toTraversable is not a member of Array[T]
Array.empty.toTraversable 
// Error: value toTraversable is not a member of String
("": String).toTraversable 

https://scastie.scala-lang.org/jaFyka1jRh2EiS7N4HYhIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants