-
Couldn't load subscription status.
- Fork 1.4k
Add accessibleM and accessibleMM macro annotations to support HKT #4332
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
Add accessibleM and accessibleMM macro annotations to support HKT #4332
Conversation
82fb2f2 to
664909e
Compare
664909e to
7b3beed
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.
Aside from the 2 comments I left, I think you've done a fantastic job and it would be great to see this merged soon! 👍
| private val typeParamToInject = { | ||
| val candidates = | ||
| moduleInfo.serviceTypeParams.filter { tp => | ||
| tp.tparams.forall(_.name == `_`) && tp.tparams.size == expectedTypeParams |
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.
tp.tparams.forall(_.name ==
_)
That's an odd check. It's legal to name type parameters in Scala, as in trait Service[F[e, a]]
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.
Yeah, it was really too strict a requirement. Fixed.
| """ | ||
| @accessibleMM[RIO] | ||
| object Module { | ||
| trait Service[-A, F[_, _]] { |
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.
It would be good to add tests also for variance annotations inside the F parameter as in:
trait Service[F[+_, _]] // should work and variance should be preserved in output code (e.g. Service[UIO] <: Service[Task])
trait Service[F[_, +_]] // should work and variance should be preserved in output code (e.g. Service[UIO] <: Service[Task])
trait Service[F[+_, +_]] // should work and variance should be preserved in output code (e.g. Service[UIO] <: Service[Task])
trait Service[F[-_, _]] // should fail because IO is not contravariant
trait Service[F[_, -_]] // should fail because IO is not contravariantThere 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 added 4 more test at the end of AccessibleMMSpec and AccessibleMSpec. They don't cover all cases due to limitations of typechecking in tests, but I hope this is better than nothing.
Thank you for your help!
042718f to
1d70037
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.
LGTM
1d70037 to
1a9c0c6
Compare
|
I had to push a small fix, as I remembered that ZIO streams are not included in ZIO. |
33f7edf to
74a0599
Compare
74a0599 to
f2a7a9e
Compare
Closes #3971
The purpose of this PR is to add
@accessibleMmacro that will support HKT and should work as followsSame for the
@accessibleMMmacroBoth
@accessibleMand@accessibleMMsupport polymorphic functions and traits as good as existing@accessibledoes.For simplicity, for now it is only possible to use type aliases defined in ZIO (i.e. you can't use custom type alias nor type lambda).