-
Couldn't load subscription status.
- Fork 1.4k
Varargs support in mockable #3292
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
Varargs support in mockable #3292
Conversation
d28f267 to
3ea7a48
Compare
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.
Great job! 🙏 If you could just remove the impure val static example and elaborate on why you introduced the class (just curious) and we're good to go!
| type SimpleImpureDefsModule = Has[SimpleImpureDefsModule.Service] | ||
| object SimpleImpureDefsModule { | ||
| trait Service { | ||
| val static: String |
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.
We don't support impure vals in ZIO Mock. In a user finds himself needing an impure val in his Service, he should instead define it as def static: String and then in the actual live implementation can implement that with a val.
The reason is that the ZIO Mocks compose layer must satisfy the contract of the service (returning an impure value), but if we do that, then the static proxy will always be called (when the layer is created). One could overcome that by overriding it with lazy val in the Mock, but that will only work in 2.x (dotty will raise a compile time error) and its not considered a good practice.
On the other hand, implementing a def in terms of lazy val (in Mock) and val (in Live) is perfectly fine.
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'll add another issue to document this and also throw a compile time error when @mockable is used in such scenario.
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 #3298
| _root_.zio.ZLayer.fromServiceM { proxy => | ||
| withRuntime.map { rts => | ||
| new $service { | ||
| class $serviceClassName extends $service { |
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.
Why this change?
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.
.replaceAll("\\{[\\n\\s]*\\};?", "") below breaks compilation for empty service: new Service()
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 see 👍
3ea7a48 to
2b2b388
Compare
|
@ioleo done |
Varargs support in mockable annotation macro together with tests for mockable annotation macro.
Unfortunately due to bugs in
Context.typecheckit's impossible to usetypeChecktests for mockable annotation. It might be possible to implement such tests with calls toscalac, though it looks quite difficult.There is also a fix for impure methods support in mockable macro (it was broken).