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
Conversation
build.sbt
Outdated
@@ -255,6 +255,10 @@ lazy val coreTests = crossProject(JSPlatform, JVMPlatform, NativePlatform) | |||
.dependsOn(testRunner) | |||
.settings(buildInfoSettings("zio")) | |||
.settings(publish / skip := true) | |||
.settings( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
b5e25b2
to
4fa246e
Compare
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") |
There was a problem hiding this comment.
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:
- What's going wrong, in detail (a user might not have ever heard of "by-name" parameters)
- 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
- What the user can do to fix the problem
There was a problem hiding this comment.
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]
──────────────────────────────────────────────────────────────────────
It's not really fixable on ZIO side, but at least better error message can be shown.
Fixes #7732
/claim #7732