Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix test.
  • Loading branch information
viirya committed Jan 11, 2017
commit 0af969ea42aee1eabb4de0595c3b25fec899062c
Original file line number Diff line number Diff line change
Expand Up @@ -348,31 +348,38 @@ object ScalaReflection extends ScalaReflection {
"make",
array :: Nil)

if (localTypeOf[scala.collection.mutable.WrappedArray[_]] <:< t.erasure) {
wrappedArray
} else {
// Convert to another type using `to`
val cls = mirror.runtimeClass(t.typeSymbol.asClass)
import scala.collection.generic.CanBuildFrom
import scala.reflect.ClassTag
val cls = mirror.runtimeClass(t.typeSymbol.asClass)
import scala.collection.generic.CanBuildFrom
import scala.reflect.ClassTag

val cbfParams = try {
// Some canBuildFrom methods take an implicit ClassTag parameter
val cbfParams = try {
cls.getDeclaredMethod("canBuildFrom", classOf[ClassTag[_]])
cls.getDeclaredMethod("canBuildFrom", classOf[ClassTag[_]])
Some(StaticInvoke(
ClassTag.getClass,
ObjectType(classOf[ClassTag[_]]),
"apply",
StaticInvoke(
ClassTag.getClass,
ObjectType(classOf[ClassTag[_]]),
"apply",
StaticInvoke(
cls,
ObjectType(classOf[Class[_]]),
"getClass"
) :: Nil
cls,
ObjectType(classOf[Class[_]]),
"getClass"
) :: Nil
} catch {
case _: NoSuchMethodException => Nil
}
) :: Nil)
} catch {
case _: NoSuchMethodException =>
try {
cls.getDeclaredMethod("canBuildFrom")
Some(Nil)
} catch {
case _: NoSuchMethodException => None
}
}

if (localTypeOf[scala.collection.mutable.WrappedArray[_]] <:< t.erasure ||
cbfParams.isEmpty) {
wrappedArray
} else {
// Convert to another type using `to`
Invoke(
wrappedArray,
"to",
Expand All @@ -381,7 +388,7 @@ object ScalaReflection extends ScalaReflection {
cls,
ObjectType(classOf[CanBuildFrom[_, _, _]]),
"canBuildFrom",
cbfParams
cbfParams.get
) :: Nil
)
}
Expand Down