Skip to content

Commit

Permalink
Scala.js-friendly ClassTag.unapply
Browse files Browse the repository at this point in the history
Use `j.l.Class.isInstance` for Scala.js, so that `unapply`
works correctly when referencing raw JavaScript classes.
  • Loading branch information
sjrd authored and adriaanm committed Feb 13, 2015
1 parent 4554a10 commit f7bc59b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/library/scala/reflect/ClassTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serial
def unapply(x: Double) : Option[T] = unapplyImpl(x, classOf[Double])
def unapply(x: Boolean) : Option[T] = unapplyImpl(x, classOf[Boolean])
def unapply(x: Unit) : Option[T] = unapplyImpl(x, classOf[Unit])

private[this] def unapplyImpl(x: Any, alternative: jClass[_] = null): Option[T] = {
val conforms = runtimeClass.isAssignableFrom(x.getClass) || (alternative != null && runtimeClass.isAssignableFrom(alternative))
val conforms = runtimeClass.isInstance(x) || (alternative != null && runtimeClass.isAssignableFrom(alternative))
if (conforms) Some(x.asInstanceOf[T]) else None
}

Expand Down

0 comments on commit f7bc59b

Please sign in to comment.