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

Zlayer issue - Ambiguous layer with opaque type #8749

Open
regis-leray opened this issue Apr 15, 2024 · 2 comments
Open

Zlayer issue - Ambiguous layer with opaque type #8749

regis-leray opened this issue Apr 15, 2024 · 2 comments

Comments

@regis-leray
Copy link
Member

regis-leray commented Apr 15, 2024

zio version 2.0.22
scala version 3.3.3

object Blah{

  case class MyService()

  opaque type A = MyService

  opaque type B = MyService

  def main(args: Array[String]): Unit = {
    val instanceA: A = MyService()
    val instanceB: B = MyService()
    
    val _ = ZLayer.make[Scope](
      ZLayer.succeed(instanceA),
      ZLayer.succeed(instanceB)
    )

  }
}

im getting the following error

──── ZLAYER ERROR ────────────────────────────────────────────────────

 Ambiguous layers! I cannot decide which to use.
 You have provided more than one layer for the following type:

   Blah.MyService is provided by:
      1. ZLayer.succeed(instanceA)
      2. ZLayer.succeed(instanceB)

──────────────────────────────────────────────────────────────────────


    val _ = ZLayer.make[Scope](

@regis-leray
Copy link
Member Author

Im going to close the ticket since the scala compiler see A =:= B as equivalent type. Need to use concrete case class or zio prelude subtype :)

@desavitsky
Copy link

desavitsky commented Apr 15, 2024

A =:= B

Isn't it only in the scope in which opaque types defined? Outside of this scope they should be different types for compiler. And the case in the issue I think can also be implemented if opaque types definition was moved outside of opaque types definition

It seems so:
https://scastie.scala-lang.org/EXwb7wUIQHm3dJn0hIO1BQ

@regis-leray regis-leray reopened this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants