Skip to content

Commit

Permalink
Add more robust type parameter checking when generating DSL wrapper m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
lloydmeta committed Apr 9, 2017
1 parent ca044de commit 4e258ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 5 additions & 7 deletions core/src/main/scala/diesel/internal/MacroImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ object MacroImpl {
val newParamss = paramss.map { params =>
params.map { param =>
param.decltpe match {
case Some(t"$tParamAsType[..$realParam]") => {
val decltpe = Some(t"$DslType[$algebraType, ..$realParam]")
case Some(Type.Apply(t: Type.Name, realParams)) if t.value == tparamName => {
val decltpe = Some(t"$DslType[$algebraType, ..$realParams]")
param.copy(decltpe = decltpe)
}
case _ => param
Expand All @@ -213,13 +213,11 @@ object MacroImpl {
val interpreterArgs: Seq[Seq[Term.Arg]] = paramss.map { params =>
params.map { param =>
param.decltpe match {
case Some(t"$tParamAsType[..$realParam]") => {
case Some(Type.Apply(t: Type.Name, _)) if t.value == tparamName => {
val term = Term.Name(param.name.value)
q"$term.apply[$tParamAsType]"
}
case _ => {
Term.Name(param.name.value)
q"$term.apply[$tparamAsType]"
}
case _ => Term.Name(param.name.value)
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions core/src/test/scala/diesel/MacroSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ class MacroSpec extends FunSpec with Matchers {
trait Maths[G[_]] {
def int(i: Int): G[Int]
def add(l: G[Int], r: G[Int]): G[Int]
def optInt(i: Option[Int]): G[Option[Int]]
def shadowedInt[G[_]](i: G[Int]): G[Int]
def mixedInts[H[_]](i: Int, optInt: Option[Int], gInt: G[Int], hInt: H[Int]): G[Int]
}

val interpreter = new Maths.Algebra[Id] {
def int(i: Int) = i
def add(l: Id[Int], r: Id[Int]) = l + r
def int(i: Int) = i
def add(l: Id[Int], r: Id[Int]) = l + r
def optInt(i: Option[Int]) = i
def shadowedInt[G[_]](i: G[Int]) = i
def mixedInts[H[_]](i: Int, optInt: Option[Int], gInt: Id[Int], hInt: H[Int]) = i
}

import Maths._
Expand Down

0 comments on commit 4e258ea

Please sign in to comment.