aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/magnolia.scala
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-06-13 14:33:25 +0200
committerJon Pretty <jon.pretty@propensive.com>2017-06-13 14:33:25 +0200
commitd1a7565a92d81a451c50d7739365d7106f63f1b7 (patch)
treef8a8694dce83dcf4d9f6183cf805e48c40f7a52c /core/src/main/scala/magnolia.scala
parent47cc95b1d02d997b611daeb59983160e98851d09 (diff)
downloadmagnolia-d1a7565a92d81a451c50d7739365d7106f63f1b7.tar.gz
magnolia-d1a7565a92d81a451c50d7739365d7106f63f1b7.tar.bz2
magnolia-d1a7565a92d81a451c50d7739365d7106f63f1b7.zip
Better error reporting
Diffstat (limited to 'core/src/main/scala/magnolia.scala')
-rw-r--r--core/src/main/scala/magnolia.scala27
1 files changed, 15 insertions, 12 deletions
diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala
index 22beec4..d2978b5 100644
--- a/core/src/main/scala/magnolia.scala
+++ b/core/src/main/scala/magnolia.scala
@@ -134,6 +134,11 @@ class Macros(val c: whitebox.Context) {
} else if(isSealedTrait) {
val subtypes = classType.get.knownDirectSubclasses.to[List]
+
+ if(subtypes.isEmpty) {
+ c.info(c.enclosingPosition, s"could not find any direct subtypes of $typeSymbol", true)
+ c.abort(c.enclosingPosition, "")
+ }
Some {
val components = subtypes.map(_.asType.toType).map { searchType =>
@@ -167,20 +172,14 @@ class Macros(val c: whitebox.Context) {
construct.map { const =>
val impl = derivationImplicit.merge
- val res = q"""{
+ q"""{
def $assignedName: $resultType = $impl.construct { sourceParameter => $const }
$assignedName
}"""
-
- try c.typecheck(res) catch {
- case e: Exception =>
- e.printStackTrace()
- }
- res
}
}
- def magnolia[T: WeakTypeTag, Typeclass: WeakTypeTag]: Tree = try {
+ def magnolia[T: WeakTypeTag, Typeclass: WeakTypeTag]: Tree = {
val genericType: Type = weakTypeOf[T]
val currentStack: Stack = recursionStack.get(c.enclosingPosition).getOrElse(Stack(List(), List()))
@@ -196,7 +195,14 @@ class Macros(val c: whitebox.Context) {
Left(c.untypecheck(c.inferImplicitValue(coDerivationType, false, false)))
} catch {
case e: Exception =>
- Right(c.untypecheck(c.inferImplicitValue(contraDerivationType)))
+ try Right(c.untypecheck(c.inferImplicitValue(contraDerivationType, false, false))) catch {
+ case e: Exception =>
+ c.info(c.enclosingPosition, s"could not find an implicit instance of "+
+ s"CovariantDerivation[$typeConstructor] or "+
+ s"ContravariantDerivation[$typeConstructor]", true)
+
+ throw e
+ }
}
if(directlyReentrant) throw DirectlyReentrantException()
@@ -235,9 +241,6 @@ class Macros(val c: whitebox.Context) {
c.abort(c.enclosingPosition, "could not infer typeclass for type $genericType")
}
- } catch {
- case DirectlyReentrantException() => ???
- case e: Exception => e.printStackTrace(); ???
}
}