question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ZLayer.wire macro fails on compile time

See original GitHub issue

I found an interesting case and extracted it from real project:

object Example {
  import zio._
  import zio.magic._

  type A = Has[A.Service]
  object A {
    trait Service {}
    val live: ULayer[A] = ZLayer.succeed(new Service {})
  }

  type B = Has[B.Service]
  object B {
    trait Service {}
    val live: ULayer[B] =
      ZLayer.succeed(new Service {})
  }

  type C = Has[C.Service]
  object C {
    trait Service {}
    val live: URLayer[A with B, C] =
      ZLayer.succeed(new Service {})
  }

  // Success
  val layer1: ULayer[A with B] = A.live >+> B.live >+> C.live

  // Failure
  val layer2: ULayer[A with B] = ZLayer.wire[A with B](A.live, B.live, C.live)
}

type mismatch;
 found   : zio.ZLayer[Example.A with Example.B with Any with Any,Nothing,Example.C with Example.A with Example.B]
    (which expands to)  zio.ZLayer[zio.Has[Example.A.Service] with zio.Has[Example.B.Service] with Any with Any,Nothing,zio.Has[Example.C.Service] with zio.Has[Example.A.Service] with zio.Has[Example.B.Service]]
 required: zio.ZLayer[Any,Nothing,zio.Has[Example.A.Service] with zio.Has[Example.B.Service]]
  val layer2: ULayer[A with B] = ZLayer.wire[A with B](A.live, B.live, C.live)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vladimirklcommented, Apr 13, 2021

Also works for me, thank you!

1reaction
hmemcpycommented, Apr 13, 2021

I confirm the latest fix is MAGICAL! It solves my issue (which is very similar to @vladimirkl’s). So thank you 😃)

BTW, this should be fixed for ZIO 2.0, right? image (the package string, it should be sesv2.live)

Read more comments on GitHub >

github_iconTop Results From Across the Web

kitlangton/zio-magic: Construct ZLayers automagically (w
Construct ZLayers automagically (w/ helpful compile-time errors) - GitHub - kitlangton/zio-magic: Construct ... ZLayer Wiring Error > provide zio.magic.
Read more >
MASTERING MODULARITY IN ZIO WITH ZLAYER - Scalac
ZIO data types for writing modular applications: ZLayer and Has. ... the -Ymacro-annotations compiler flag so we will be able to use some...
Read more >
adamw/macwire - Gitter
Since version 0.10 it doesn't use scala-reflect, so no problems with graal native image, concurrency etc. It's not compile-time, but you can test...
Read more >
Kit Langton on Twitter: "Today, I figured out how to construct ...
Today, I figured out how to construct ZLayers at compile time, replete w/ targeted error messages for missing dependencies.
Read more >
Structuring ZIO 2 applications - SoftwareMill
Or we could use ZLayer.make , which is a macro doing this for us (hence everything happens at compile-time, generating the appropriate code) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found