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.scala45
1 files changed, 22 insertions, 23 deletions
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index 2e7dae8..f55dfa7 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -1,8 +1,6 @@
package magnolia
-import scala.util.control.NonFatal
-import scala.reflect._
-import macros._
+import scala.reflect._, macros._
import scala.collection.immutable.ListMap
import language.existentials
import language.higherKinds
@@ -113,7 +111,7 @@ object Magnolia {
)
}
val firstParamBlock = combineClass.asType.toType.decl(term).asTerm.asMethod.paramLists.head
- if (firstParamBlock.lengthCompare(1) != 0)
+ if (firstParamBlock.length != 1)
c.abort(c.enclosingPosition,
s"magnolia: the method `combine` should take a single parameter of type $expected")
}
@@ -125,9 +123,9 @@ object Magnolia {
def findType(key: Type): Option[TermName] =
recursionStack(c.enclosingPosition).frames.find(_.genericType == key).map(_.termName(c))
- final case class Typeclass(typ: c.Type, tree: c.Tree)
+ case class Typeclass(typ: c.Type, tree: c.Tree)
- def recurse[A](path: TypePath, key: Type, value: TermName)(fn: => A): Option[A] = {
+ def recurse[T](path: TypePath, key: Type, value: TermName)(fn: => T): Option[T] = {
val oldRecursionStack = recursionStack.get(c.enclosingPosition)
recursionStack = recursionStack.updated(
c.enclosingPosition,
@@ -137,7 +135,7 @@ object Magnolia {
)
try Some(fn)
- catch { case NonFatal(_) => None } finally {
+ catch { case e: Exception => None } finally {
val currentStack = recursionStack(c.enclosingPosition)
recursionStack = recursionStack.updated(c.enclosingPosition, currentStack.pop())
}
@@ -294,7 +292,7 @@ object Magnolia {
m.asMethod
}
- final case class CaseParam(sym: c.universe.MethodSymbol,
+ case class CaseParam(sym: c.universe.MethodSymbol,
repeated: Boolean,
typeclass: c.Tree,
paramType: c.Type,
@@ -507,14 +505,15 @@ 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): Subtype[Tc, T] =
- new Subtype[Tc, T] with PartialFunction[T, S] {
+ def subtype[Tc[_], T, S <: T](name: String, tc: => Tc[S], isType: T => Boolean, asType: T => S) =
+ new Subtype[Tc, T] {
type SType = S
def label: String = name
def typeclass: Tc[SType] = tc
- def cast: PartialFunction[T, SType] = this
- def isDefinedAt(t: T) = isType(t)
- def apply(t: T): SType = asType(t)
+ def cast: PartialFunction[T, SType] = new PartialFunction[T, S] {
+ def isDefinedAt(t: T) = isType(t)
+ def apply(t: T): SType = asType(t)
+ }
}
/** constructs a new [[Param]] instance
@@ -525,7 +524,7 @@ object Magnolia {
isRepeated: Boolean,
typeclassParam: Tc[P],
defaultVal: => Option[P],
- deref: T => P): Param[Tc, T] = new Param[Tc, T] {
+ deref: T => P) = new Param[Tc, T] {
type PType = P
def label: String = name
def repeated: Boolean = isRepeated
@@ -542,31 +541,31 @@ object Magnolia {
obj: Boolean,
valClass: Boolean,
params: Array[Param[Tc, T]],
- constructor: (Param[Tc, T] => Any) => T): CaseClass[Tc, T] =
+ constructor: (Param[Tc, T] => Any) => T) =
new CaseClass[Tc, T](name, obj, valClass, params) {
def construct[R](param: Param[Tc, T] => R): T = constructor(param)
}
}
-private[magnolia] final case class DirectlyReentrantException()
+private[magnolia] case class DirectlyReentrantException()
extends Exception("attempt to recurse directly")
private[magnolia] object Deferred { def apply[T](method: String): T = ??? }
private[magnolia] object CompileTimeState {
- sealed abstract class TypePath(path: String) { override def toString = path }
- final case class CoproductType(typeName: String) extends TypePath(s"coproduct type $typeName")
+ sealed class TypePath(path: String) { override def toString = path }
+ case class CoproductType(typeName: String) extends TypePath(s"coproduct type $typeName")
- final case class ProductType(paramName: String, typeName: String)
+ case class ProductType(paramName: String, typeName: String)
extends TypePath(s"parameter '$paramName' of product type $typeName")
- final case class ChainedImplicit(typeName: String)
+ case class ChainedImplicit(typeName: String)
extends TypePath(s"chained implicit of type $typeName")
- final case class ImplicitNotFound(genericType: String, path: List[TypePath])
+ case class ImplicitNotFound(genericType: String, path: List[TypePath])
- final case class Stack(cache: Map[whitebox.Context#Type, Option[whitebox.Context#Tree]],
+ case class Stack(cache: Map[whitebox.Context#Type, Option[whitebox.Context#Tree]],
frames: List[Frame],
errors: List[ImplicitNotFound]) {
@@ -584,7 +583,7 @@ private[magnolia] object CompileTimeState {
def pop(): Stack = Stack(cache, frames.tail, errors)
}
- final case class Frame(path: TypePath,
+ case class Frame(path: TypePath,
genericType: whitebox.Context#Type,
term: whitebox.Context#TermName) {
def termName(c: whitebox.Context): c.TermName = term.asInstanceOf[c.TermName]