aboutsummaryrefslogtreecommitdiff
path: root/core/shared/src/main/scala/magnolia.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/shared/src/main/scala/magnolia.scala')
-rw-r--r--core/shared/src/main/scala/magnolia.scala14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index f55dfa7..68c0f4f 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -1,6 +1,7 @@
package magnolia
-import scala.reflect._, macros._
+import scala.reflect._
+import macros._
import scala.collection.immutable.ListMap
import language.existentials
import language.higherKinds
@@ -505,15 +506,14 @@ object Magnolia {
*
* This method is intended to be called only from code generated by the Magnolia macro, and
* should not be called directly from users' code. */
- def subtype[Tc[_], T, S <: T](name: String, tc: => Tc[S], isType: T => Boolean, asType: T => S) =
- new Subtype[Tc, T] {
+ def subtype[Tc[_], T, S <: T](name: String, tc: => Tc[S], isType: T => Boolean, asType: T => S): Subtype[Tc, T] =
+ new Subtype[Tc, T] with PartialFunction[T, S] {
type SType = S
def label: String = name
def typeclass: Tc[SType] = tc
- def cast: PartialFunction[T, SType] = new PartialFunction[T, S] {
- def isDefinedAt(t: T) = isType(t)
- def apply(t: T): SType = asType(t)
- }
+ def cast: PartialFunction[T, SType] = this
+ def isDefinedAt(t: T) = isType(t)
+ def apply(t: T): SType = asType(t)
}
/** constructs a new [[Param]] instance