Skip to content

Commit c426dec

Browse files
committed
fix compile errors in latest Scala 2.13
- scala/scala@1e21c91#diff-c4d00ae1df2a449ae3d28a7a4469e28a - https://scala-ci.typesafe.com/job/scala-2.13.x-integrate-community-build/1187/consoleFull ``` [scala-java8-compat] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.12/project-builds/scala-java8-compat-e21fca9479a0769dd077af3a1d088d2f68798316/src/main/scala/scala/compat/java8/converterImpl/StepConverters.scala:19: type mismatch; [scala-java8-compat] [error] found : Array[_$2] where type _$2 [scala-java8-compat] [error] required: Array[A] [scala-java8-compat] [error] Note: implicit method richArraySeqCanStep is not applicable here because it comes after the application point and it lacks an explicit result type [scala-java8-compat] [error] implicit def richArraySeqCanStep[A](underlying: collection.mutable.ArraySeq[A]) = new RichArrayCanStep[A](underlying.array) [scala-java8-compat] [error] ^ [scala-java8-compat] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.12/project-builds/scala-java8-compat-e21fca9479a0769dd077af3a1d088d2f68798316/src/main/scala/scala/compat/java8/StreamConverters.scala:200: type mismatch; [scala-java8-compat] [error] found : Array[_$2] where type _$2 [scala-java8-compat] [error] required: Array[Double] [scala-java8-compat] [error] Note: implicit value accumulateLongStepper is not applicable here because it comes after the application point and it lacks an explicit result type [scala-java8-compat] [error] def seqStream: DoubleStream = java.util.Arrays.stream(a.array) [scala-java8-compat] [error] ^ [scala-java8-compat] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.12/project-builds/scala-java8-compat-e21fca9479a0769dd077af3a1d088d2f68798316/src/main/scala/scala/compat/java8/StreamConverters.scala:206: type mismatch; [scala-java8-compat] [error] found : Array[_$2] where type _$2 [scala-java8-compat] [error] required: Array[Int] [scala-java8-compat] [error] Note: implicit value accumulateLongStepper is not applicable here because it comes after the application point and it lacks an explicit result type [scala-java8-compat] [error] def seqStream: IntStream = java.util.Arrays.stream(a.array) [scala-java8-compat] [error] ^ [scala-java8-compat] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.12/project-builds/scala-java8-compat-e21fca9479a0769dd077af3a1d088d2f68798316/src/main/scala/scala/compat/java8/StreamConverters.scala:212: type mismatch; [scala-java8-compat] [error] found : Array[_$2] where type _$2 [scala-java8-compat] [error] required: Array[Long] [scala-java8-compat] [error] Note: implicit value accumulateLongStepper is not applicable here because it comes after the application point and it lacks an explicit result type [scala-java8-compat] [error] def seqStream: LongStream = java.util.Arrays.stream(a.array) [scala-java8-compat] [error] ^ ```
1 parent 771f9ee commit c426dec

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/scala/scala/compat/java8/StreamConverters.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scala.language.higherKinds
55
import java.util.stream._
66
import scala.compat.java8.collectionImpl._
77
import scala.compat.java8.converterImpl._
8+
import scala.reflect.ClassTag
89

910
/** Classes or objects implementing this trait create streams suitable for sequential use */
1011
trait MakesSequentialStream[T, SS <: java.util.stream.BaseStream[_, SS]] extends Any {
@@ -177,6 +178,13 @@ extends Priority1StreamConverters
177178
with converterImpl.Priority1StepConverters
178179
with converterImpl.Priority1AccumulatorConverters
179180
{
181+
private[java8] def unsafeArrayIfPossible[A](a: collection.mutable.ArraySeq[A])(implicit c: ClassTag[A]): Array[A] = {
182+
if (a.elemTag == c)
183+
a.array.asInstanceOf[Array[A]]
184+
else
185+
a.toArray
186+
}
187+
180188
implicit final class EnrichDoubleArrayWithStream(private val a: Array[Double])
181189
extends AnyVal with MakesSequentialStream[Double, DoubleStream] with MakesParallelStream[Double, DoubleStream] {
182190
def seqStream: DoubleStream = java.util.Arrays.stream(a)
@@ -197,19 +205,19 @@ with converterImpl.Priority1AccumulatorConverters
197205

198206
implicit final class EnrichDoubleArraySeqWithStream(private val a: collection.mutable.ArraySeq[Double])
199207
extends AnyVal with MakesSequentialStream[Double, DoubleStream] with MakesParallelStream[Double, DoubleStream] {
200-
def seqStream: DoubleStream = java.util.Arrays.stream(a.array)
208+
def seqStream: DoubleStream = java.util.Arrays.stream(unsafeArrayIfPossible(a))
201209
def parStream: DoubleStream = seqStream.parallel
202210
}
203211

204212
implicit final class EnrichIntArraySeqWithStream(private val a: collection.mutable.ArraySeq[Int])
205213
extends AnyVal with MakesSequentialStream[Int, IntStream] with MakesParallelStream[Int, IntStream] {
206-
def seqStream: IntStream = java.util.Arrays.stream(a.array)
214+
def seqStream: IntStream = java.util.Arrays.stream(unsafeArrayIfPossible(a))
207215
def parStream: IntStream = seqStream.parallel
208216
}
209217

210218
implicit final class EnrichLongArraySeqWithStream(private val a: collection.mutable.ArraySeq[Long])
211219
extends AnyVal with MakesSequentialStream[Long, LongStream] with MakesParallelStream[Long, LongStream] {
212-
def seqStream: LongStream = java.util.Arrays.stream(a.array)
220+
def seqStream: LongStream = java.util.Arrays.stream(unsafeArrayIfPossible(a))
213221
def parStream: LongStream = seqStream.parallel
214222
}
215223

src/main/scala/scala/compat/java8/converterImpl/StepConverters.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package scala.compat.java8.converterImpl
1+
package scala.compat.java8
2+
package converterImpl
23

34
import language.implicitConversions
5+
import scala.reflect.ClassTag
46

57
trait Priority3StepConverters {
68
implicit def richIterableCanStep[A](underlying: Iterable[A]) = new RichIterableCanStep(underlying)
@@ -16,7 +18,7 @@ trait Priority1StepConverters extends Priority2StepConverters {
1618
implicit def richDefaultHashMapCanStep[K, V](underlying: collection.mutable.HashMap[K, V]) = new RichHashMapCanStep[K, V](underlying)
1719
implicit def richLinkedHashMapCanStep[K, V](underlying: collection.mutable.LinkedHashMap[K, V]) = new RichLinkedHashMapCanStep[K, V](underlying)
1820
implicit def richArrayCanStep[A](underlying: Array[A]) = new RichArrayCanStep[A](underlying)
19-
implicit def richArraySeqCanStep[A](underlying: collection.mutable.ArraySeq[A]) = new RichArrayCanStep[A](underlying.array)
21+
implicit def richArraySeqCanStep[A: ClassTag](underlying: collection.mutable.ArraySeq[A]) = new RichArrayCanStep[A](StreamConverters.unsafeArrayIfPossible(underlying))
2022
implicit def richHashSetCanStep[A](underlying: collection.mutable.HashSet[A]) = new RichHashSetCanStep[A](underlying)
2123
implicit def richIteratorCanStep[A](underlying: Iterator[A]) = new RichIteratorCanStep(underlying)
2224
implicit def richImmHashMapCanStep[K, V](underlying: collection.immutable.HashMap[K, V]) = new RichImmHashMapCanStep[K, V](underlying)

0 commit comments

Comments
 (0)