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

Show message when using unsupported by-name parameters #8117

Merged
merged 4 commits into from Jun 13, 2023

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
@@ -255,6 +255,10 @@ lazy val coreTests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.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
21 checks passed
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