Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Lazy for tagged types #797

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -316,4 +316,21 @@ class LazyStrictTests {
"lazily[W[String, Int]]", "No W\\[String, Int]"
)
}

@Test
def testInteractionWithTaggedTypes: Unit = {
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]]]
}
}