-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Simple application of opaque types, extension methods hangs in runtime #11403
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
Comments
Why does it work properly when I manually summon the instance though? |
Here's the translation of final lazy given val given_Eq_UserId: Eq[test$package.UserId] =
{
println("bar")
Eq.apply[String](UserId.given_Eq_UserId)
} It needs to find an instance for There's no ambiguity with the |
I still don't understand why this would cause an issue when in |
It works when an instance of https://scastie.scala-lang.org/arturopala/whZCf9PuSwigZxjwc4Kw4w
|
That's... Even more surprising? |
I just tried it and I couldn't reproduce that behavior, it loops in the same way (you can check what code is actually being generated by adding
Notice that in this example given Eq[UserId] =
import Eq.given // Give precedence to the givens in Eq
println("bar")
Eq[String] (you can be even more explicit by writing |
Ouch, that's true - I must have checked with some other changes in place when I last tried this way. Sorry for that.
Makes sense, thanks for explaining. Is there anything in plans to support automatic derivation of instances for opaque types? |
Nope, I don't think this has ever been really discussed, so you can try starting a thread in https://contributors.scala-lang.org/, I think it's an interesting thing to explore but it will require some careful thought, the first thing to do would be to carefully study the history of GeneralizedNewtypeDeriving and roles in GHC and see how much of that is relevant for us. |
Sounds good :) I suppose this kind of feature could come in a later 3.x without breaking on the binary/tasty level? |
Yep! (but before adding complexity to the language, it's also worth asking first if |
I'm going to quote that post quite often from now on 😂 it's good to see "you might not need newtypes" coming from a compiler developer... |
I mean, it seems that no one believes me so it's entirely possible I'm wrong 😄 |
Compiler version
3.0.0-M3
Minimized code
as scastie: https://scastie.scala-lang.org/3YbjmeaUTYWzwBOQOdRt8g
Output
bar <hangs now>
Expectation
outputs
bar
, thentrue
, then exits.More context
This doesn't happen when
Eq[UserId].eqv(..., ...)
is used instead.The text was updated successfully, but these errors were encountered: