Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #66 from mschuwalow/add-warning
Browse files Browse the repository at this point in the history
add warnings for mix derivation
  • Loading branch information
mschuwalow authored Nov 25, 2019
2 parents 26a00c8 + 586ccc0 commit 4ed2a5e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/shared/src/main/scala/zio/macros/delegate/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,22 @@ private[macros] class Macros(val c: Context) {

// aT may extend a class
//bT may not as it will be mixed in
preconditions(
check(
(!aTT.typeSymbol.isFinal -> s"${aTT.typeSymbol.toString()} must be nonfinal class or trait.") ::
aTTComps
.filterNot(_.typeSymbol.asClass.isTrait)
.map(
t =>
t.decls
.filter(
s =>
s.isMethod && {
val m = s.asMethod
m.isConstructor && m.paramLists.flatten.isEmpty
}
)
.nonEmpty -> s"${t.typeSymbol.toString()} needs to have an no-arg constructor."
) ++
bTTComps.map(t => t.typeSymbol.asClass.isTrait -> s"${t.typeSymbol.toString()} needs to be a trait."): _*
)

Expand Down Expand Up @@ -172,7 +186,7 @@ private[macros] class Macros(val c: Context) {

annottees.map(_.tree) match {
case (valDecl: ValDef) :: (classDecl: ClassDef) :: Nil =>
preconditions(
check(
(classDecl.tparams.isEmpty) -> "Classes with generic parameters are not currently supported."
)
val modified = modifiedClass(classDecl, valDecl)
Expand Down Expand Up @@ -259,7 +273,7 @@ private[macros] class Macros(val c: Context) {
final private[this] def abort(s: String) =
c.abort(c.enclosingPosition, s)

final private[this] def preconditions(conds: (Boolean, String)*): Unit =
final private[this] def check(conds: (Boolean, String)*): Unit =
conds.foreach {
case (cond, s) =>
if (!cond) abort(s)
Expand Down

0 comments on commit 4ed2a5e

Please sign in to comment.