-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Confusing interaction between opaque types and extension methods #9880
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
I don't see what could be done here. |
We could print a warning on obviously infinite loops (scala 2 does that for |
Ran in to this limitation again recently: object Module1:
opaque type State[S, +A] = S => (S, A)
object State:
extension [S, A](self: State[S, A])
def map[B](f: A => B): State[S, B] =
s => { val (s2, a) = self(s); (s2, f(a)) }
object Module2:
import Module1.State
trait RNG
opaque type Gen[+A] = State[RNG, A]
object Gen:
extension [A](self: Gen[A])
def map[B](f: A => B): Gen[B] =
State.map(self)(f) To implement |
Not that I can think of, instead I would recommend using a plain old class. |
I don't want to give up on using opaque types that easily. :) Directly invoking |
Yes, that's official syntax, so no worry that it might get outlawed. |
Perhaps some pinhole linting can be done but otherwise this looks like a candidate FAQ. |
Similar linting is now done for implicit definitions and should be easy to extend to extensions or even all definitions: #13589 |
Broadens Martin's fix for scala#13542 Fixes scala#9880 Also, exempt Boolean's && and || methods, which aren't set up as having by-name parameters. Co-authored-by: Dale Wijnand <[email protected]>
Minimized code
Output
Length is printed and then an infinite loop is encountered on
b.size
Expectation
Array[Byte]
doesn't have asize
member so(self: Array[Byte])
is lifted toBytes
instead of picking upArrayOps
implicit conversion. This seems like a pretty big gotcha but not sure how to improve.The text was updated successfully, but these errors were encountered: