Skip to content

Commit

Permalink
Fix Lazy for tagged types
Browse files Browse the repository at this point in the history
Fixes #584
  • Loading branch information
joroKr21 committed Dec 24, 2017
1 parent 9814604 commit 8a4680b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/lazy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ trait OpenImplicitMacros {
def openImplicitTpeParam: Option[Type] =
openImplicitTpe.map {
case TypeRef(_, _, List(tpe)) =>
tpe.map(_.dealias)
tpe.dealias
case other =>
c.abort(c.enclosingPosition, s"Bad materialization: $other")
}
Expand Down
27 changes: 15 additions & 12 deletions core/src/test/scala/shapeless/labelledgeneric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object ScalazTaggedAux {
def apply(): String
}

object TC {
object TC extends TCLowPriority {
implicit val intTC: TC[Int] =
new TC[Int] {
def apply() = "Int"
Expand All @@ -114,22 +114,13 @@ object ScalazTaggedAux {
def apply() = "HNil"
}

implicit def hconsTCTagged[K <: Symbol, H, HT, T <: HList](implicit
key: Witness.Aux[K],
headTC: Lazy[TC[H @@ HT]],
tailTC: Lazy[TC[T]]
): TC[FieldType[K, H @@ HT] :: T] =
new TC[FieldType[K, H @@ HT] :: T] {
def apply() = s"${key.value.name}: ${headTC.value()} :: ${tailTC.value()}"
}

implicit def hconsTC[K <: Symbol, H, T <: HList](implicit
key: Witness.Aux[K],
headTC: Lazy[TC[H]],
tailTC: Lazy[TC[T]]
tailTC: TC[T]
): TC[FieldType[K, H] :: T] =
new TC[FieldType[K, H] :: T] {
def apply() = s"${key.value.name}: ${headTC.value()} :: ${tailTC.value()}"
def apply() = s"${key.value.name}: ${headTC.value()} :: ${tailTC()}"
}

implicit def projectTC[F, G](implicit
Expand All @@ -140,6 +131,18 @@ object ScalazTaggedAux {
def apply() = s"Proj(${tc.value()})"
}
}

abstract class TCLowPriority {
// FIXME: Workaround #309
implicit def hconsTCTagged[K <: Symbol, H, HT, T <: HList](implicit
key: Witness.Aux[K],
headTC: Lazy[TC[H @@ HT]],
tailTC: TC[T]
): TC[FieldType[K, H @@ HT] :: T] =
new TC[FieldType[K, H @@ HT] :: T] {
def apply() = s"${key.value.name}: ${headTC.value()} :: ${tailTC()}"
}
}
}

class LabelledGenericTests {
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/scala/shapeless/lazy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,21 @@ class LazyStrictTests {
"lazily[W[String, Int]]", "No W\\[String, Int]"
)
}

@Test
def testInteractionWithTaggedTypes {
import tag._

class Readable[A]
trait IdTag
type Id = String @@ IdTag

implicit def taggedStringReadable[T, M[_, _]](
implicit ev: String @@ T =:= M[String, T]
): Readable[M[String, T]] = new Readable

implicitly[Readable[Id]]
implicitly[Lazy[Readable[Id]]]
implicitly[Strict[Readable[Id]]]
}
}

0 comments on commit 8a4680b

Please sign in to comment.