Skip to content

Commit

Permalink
Remove compile warnings in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Nov 8, 2023
1 parent b30deb8 commit 1d84851
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/eucalyptus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ object Eucalyptus:

def route(routes: Expr[PartialFunction[Entry, Any]], monitor: Expr[Monitor])(using Quotes): Expr[Log] =
import quotes.reflect.*

def invalidRoutes(): Nothing = fail(msg"the routes must be specified as one or more case clauses")

val count: Int = routes.asTerm match
case Inlined(_, _, Block(List(defDef), term)) => defDef match
case DefDef(ident, scrutineeType, returnType, Some(Match(matchId, caseDefs))) => caseDefs.length
case Inlined(_, _, Block(List(DefDef(_, _, _, Some(Match(_, caseDefs)))), _)) => caseDefs.length
case _ => invalidRoutes()

'{
val loggers: Array[Logger | Null] = new Array(${Expr(count)})
Expand All @@ -59,7 +61,7 @@ object Eucalyptus:
case Inlined(_, _, Block(List(defDef), term)) => defDef match
case DefDef(ident, scrutineeType, returnType, Some(Match(matchId, caseDefs))) =>
val caseDef = caseDefs(index) match
case CaseDef(pattern, guard, target) => target.asExpr match
case CaseDef(pattern, guard, target) => (target.asExpr: @unchecked) match
case '{$target: targetType} =>
def typeName = TypeRepr.of[targetType].show

Expand All @@ -80,6 +82,12 @@ object Eucalyptus:
List(caseDef))))

Block(List(definition), term).asExprOf[PartialFunction[Entry, Any]]

case _ =>
invalidRoutes()

case _ =>
invalidRoutes()

def recur(index: Int, expr: Expr[Unit]): Expr[Unit] = if index >= count then expr else '{
$expr
Expand Down

0 comments on commit 1d84851

Please sign in to comment.