-
-
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
Compilation error with context bounds #1259
Comments
Thanks for the bug report. I am not sure when we will have time to investigate. |
I had a look into the issue in Scala 2.13 and as far as I can see the issue is located in the lens's modifyF method because it has a context bound for cats.Functor. Due to macro magic, the Functor evidence is named like it were the first evidence in the source file, i.e. like the evidence for Foo of the enclosing class A, so the evidence for Foo is shadowed and hence unavailable in modifyF's function body where it is needed for copy. That means one workaround for the issue in Scala 2.13 is putting another class with a context bound above the case class to rename the evidences below it, like this:
or by explicitly naming the implicit parameter:
|
Thanks for investigating. Do you think it will solve the problem if we change https://github.com/optics-dev/Monocle/blob/master/macro/src/main/scala-2.x/monocle/macros/internal/Macro.scala#L100 from:
to:
|
Will (mostly) solve optics-dev#1259 for Scala 2.13.
I suggest using a freshName too, to make a shadowing conflict less likely. I created a (naive) PR accordingly. |
Will (mostly) solve #1259 for Scala 2.13.
Good call, I completely forgot about |
Thanks for the quick merge! A release for this fix is not needed from my end. |
This use case is a bit unusual @NTPape - usually typeclass bounds are declared at the methods where they are required, rather that at the class constructor level. YAGNI is one reason, there's no physical reason why the Another reason is that creating an instance of Are you sure really need us to support this use case? |
Oh, I didn't notice that the discussion also moved back here from the PR. The minimal example was somewhat artificially constructed to produce the implicit parameter name shadowing of the context bounds that was observed in Scala 2.13. It just so happened that it also fails in Scala 3 but for totally different reasons as we know now. For Scala 3 a minimal example would just be a lens to a case field of a case class with any (positive) number of implicit parameters (including context bounds.) These will both fail to compile: import monocle.macros.GenLens
case class Test1(i: Int)(implicit j: Int)
GenLens[Test1](_.i)
trait Foo[T]
case class Test2[T: Foo](t: T)
GenLens[Test2[Int]](_.t) Is that really too unusual? |
Hello there!
Compilation of the following code will fail
in Scala 3 with the following error
and in Scala 2.13 with
Interestingly, the last version that appears to work is 1.5.1-cats on Scala 2.11 (but not on Scala 2.12.)
The text was updated successfully, but these errors were encountered: