ZLayer.wire macro fails on compile time
See original GitHub issueI 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:
- Created 2 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also works for me, thank you!
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? (the
package
string, it should besesv2.live
)