-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Fix compilation of lenses with context bounds in Scala 3 #1267
base: master
Are you sure you want to change the base?
Conversation
I did exactly what the error message said: try to eta expand the Term if it's not an Expr yet. This should have no influence on working code because for all code where it already compiles, i.e. asExpr succeeds, isExpr is already true and hence eta expanding would be skipped. |
I had to move the |
👀
…On Mon, 28 Feb 2022, 11:20 pm Julien Truffaut, ***@***.***> wrote:
Thanks @NTPape <https://github.com/NTPape> ! @kenbot
<https://github.com/kenbot> would you mind to review this PR when you
have time?
—
Reply to this email directly, view it on GitHub
<#1267 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACNIYZE2MG4LGQ4SXXCYJLU5NSB5ANCNFSM5PLQK4HA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Great work @NTPape, thanks! I'll need more time to understand the nuts & bolts, I'll write up some more tonight. Tbh I assume the internal bits are fine, but it interacts with the architecture in an interesting way, which I'll explain here. First up, sorry I haven't documented the Focus architecture at all, so this isn't terribly obvious and makes it harder to contribute. Each feature is split into a "Parser", which interprets the user expression into list of The Parser side never directly fails the compiler; it returns The Generator side has no concept of an error; all the decisions & validation & vetting is supposed to happen on the Parser side, and the Now your code has compiler errors directly thrown by the Generator side; if all the implicit searching can be done on the Parser side, then that's easy, we should move it there, and package failure data in a However, if for whatever reason it's impossible or unwise to do the checks in the Parser and it has to be done by the Generator, then the current architecture is broken, and we need to rethink how the whole Monocle Focus code is structured. I'm pretty sure this won't be the case though. Good luck - feel free to have a crack at the refactor, but if you like I'm happy to do it when I have time if it feels a bit daunting, especially given the dearth of documentation. |
Thanks for the detailed explanation, @kenbot! I gave it a quick go and the issue I'm running into is lifting the FocusResult of a splice into the surrounding expression. I.e. (fromType.asType, toType.asType) match {
case ('[f], '[t]) =>
'{
(to: t) => ${
etaExpandIfNecessary(
Select.overloaded(companion, "apply", fromTypeArgs, List('{ to }.asTerm))
).asExprOf[f]
}
}.asTerm)
} Is there a nice way to lift the FocusResult into the surrounding expression, or is there another way how to get a parameter for the overload resolution? |
@NTPape Check my comment on #1259 - if you don't end up needing the use case maybe all we do is intercept the context-bounds-constructor-case-class and make a nicer error message. If you're still keen, here's what it looks like: The feature we're dealing with is Have a look at the Line 25 in 21a37a0
In your case, we need to funnel a bit more stuff through, so that
Lmk if you get stuck |
b911eca
to
5d0d6cc
Compare
Sorry, my last comment was a bit too concise and without having had uploaded the code yet, it was unnecessarily difficult to understand my question and to follow the current state of my attempt. I have now uploaded a working version. As far as I understand, it is necessary to move the setter creation completely into the parser then, because only in the expression I also used the hacky FocusResult lifting via throwing exceptions for now because I'm not aware of a nicer way. Is this going in the right direction or am I on the wrong track here? Thanks for your help! |
Yep, we're not there yet, but much closer & heading in the right direction!
I'll take a closer look tonight.
…On Fri, 4 Mar 2022 at 09:10, NTPape ***@***.***> wrote:
Sorry, my last comment was a bit too concise and without having had
uploaded the code yet, it was unnecessarily difficult to understand my
question and to follow the current state of my attempt. I have now uploaded
a working version.
As far as I understand, it is necessary to move the setter creation
completely into the parser then, because only in the expression (to: To)
=> fromCompanion.apply(to) the type parameters of from become initialized
in a way which allows for implicit search for values which needs these type
parameters. (One cannot search for Foo[T] without knowing what T is, but in
the expression above it becomes A.this.T in the spec for example, which can
be found.)
I also used the hacky FocusResult lifting via throwing exceptions for now
because I'm not aware of a nicer way.
Is this going in the right direction or am I on the wrong track here?
Thanks for your help!
—
Reply to this email directly, view it on GitHub
<#1267 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACNIY3GQGJ3FVJTHVLVX7LU6E2D3ANCNFSM5PLQK4HA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
One thing that occurred to me is that it might be better to make this use
case an entirely new feature, say `SelectOnlyFieldWithContext` or something
like that, in the same way that `SelectOnlyField` is a special case of
`SelectField`. That way we can leave all the working code unmolested
and put all the complexity for this edge case in it's own bucket.
What do you think?
Btw, there should be no need to modify the `SelectField` feature - it
doesn't need to create a `reverseGet`, so it doesn't need the companion
object and doesn't need to care in the slightest about context bounds.
…On Fri, 4 Mar 2022 at 09:13, Ken Scambler ***@***.***> wrote:
Yep, we're not there yet, but much closer & heading in the right
direction! I'll take a closer look tonight.
On Fri, 4 Mar 2022 at 09:10, NTPape ***@***.***> wrote:
> Sorry, my last comment was a bit too concise and without having had
> uploaded the code yet, it was unnecessarily difficult to understand my
> question and to follow the current state of my attempt. I have now uploaded
> a working version.
>
> As far as I understand, it is necessary to move the setter creation
> completely into the parser then, because only in the expression (to: To)
> => fromCompanion.apply(to) the type parameters of from become
> initialized in a way which allows for implicit search for values which
> needs these type parameters. (One cannot search for Foo[T] without knowing
> what T is, but in the expression above it becomes A.this.T in the spec for
> example, which can be found.)
>
> I also used the hacky FocusResult lifting via throwing exceptions for now
> because I'm not aware of a nicer way.
>
> Is this going in the right direction or am I on the wrong track here?
> Thanks for your help!
>
> —
> Reply to this email directly, view it on GitHub
> <#1267 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AACNIY3GQGJ3FVJTHVLVX7LU6E2D3ANCNFSM5PLQK4HA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Yes, we can split it up into Select(Only)FieldWithImplicits and without implicits to not touch the current implementation, good point! I will do that tomorrow. We need it for both SelectField and SelectOnlyField because both companion.apply as well as the copy method have the same type parameters as the case class including context bounds and including additional parameter sets for the case class which might contain implicit value parameters. |
I did the split now and merged the Select(Only)Field parsers and generators because they are so similar. Can you have a look again? |
c3eff55
to
4ba0472
Compare
Fix compilation error when case class has a method named like a case field
Hey thanks for all this @NTPape - sorry I've been a bit busy, I'll try to get some time to take a look soon. |
Implement support of focusing into case classes with implicit parameters.
Introduce more specific error cases when trying to focus onto non-case fields, or when trying to focus on a case class with multiple (non-implicit) parameter sets.
Fix compilation exception when trying to focus onto a case field which has a method with the same name in the same case class.
Fixes #1259