Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@andrzejressel
Copy link
Contributor

@andrzejressel andrzejressel commented May 14, 2023

It's not really fixable on ZIO side, but at least better error message can be shown.

Fixes #7732
/claim #7732

build.sbt Outdated
.dependsOn(testRunner)
.settings(buildInfoSettings("zio"))
.settings(publish / skip := true)
.settings(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the typecheck operator in ZIO Test for this. There is no need for a third party dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@andrzejressel
Copy link
Contributor Author

andrzejressel commented May 14, 2023

I forgot about copy one ... I'll add it

EDIT: I've tested copy and cannot reproduce it - my guess is that propably it was only the by-name thing

for (layer <- layers) {
layer.tree match {
case apply @ Apply(_, Block(_, _) :: Nil) => {
c.abort(layer.tree.pos, "Cannot use by-name parameters")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tweak this error message to explain:

  1. What's going wrong, in detail (a user might not have ever heard of "by-name" parameters)
  2. Why it's going wrong, e.g., what problem is introduced by by-name parameters that prevents their invocation from appearing as input to provide
  3. What the user can do to fix the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created following error message:

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

 Due to bug in Scala 2 compiler invoking methods with by-name parameters in provide/provideSome method does not work
 def createLayerByName(i: Int, x: => MyLayer): zio.ULayer[MyLayer]

 Bug can be workarounded in following ways:

 1. Assign method output to temporary variable
    ZLayer.provide(createLayerByName(...))
    ↓↓↓
    val temp = createLayerByName(...)
    ZLayer.provide(temp)

 2. Replace by-name parameter with lambda:
    def createLayerByName(i: Int, x: => MyLayer): zio.ULayer[MyLayer]
    ↓↓↓
    def createLayerByName(i: Int, x: () => MyLayer): zio.ULayer[MyLayer]

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

@jdegoes jdegoes merged commit a0e2935 into zio:series/2.x Jun 13, 2023
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

Successfully merging this pull request may close these issues.

Error in the provide macro when using case class copy

3 participants