-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't use forwarders in closure implementation #4446
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
Labels
Comments
Here is an example where the captured outer reference prevents a partial function from being serialisable: class Foo {
def foo: PartialFunction[Int, Int] = { case x => x + 1 }
}
object Test {
def serializeDeserialize[T <: AnyRef](obj: T): T = {
import java.io._
val buffer = new ByteArrayOutputStream
val out = new ObjectOutputStream(buffer)
out.writeObject(obj)
val in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray))
in.readObject.asInstanceOf[T]
}
def main(args: Array[String]): Unit = {
val adder = serializeDeserialize((new Foo).foo)
assert(adder(1) == 2)
}
}
|
Fixing #4438 would make this fix trivial |
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
May 30, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 1, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 1, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 1, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 3, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 4, 2018
allanrenucci
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 6, 2018
allanrenucci
added a commit
that referenced
this issue
Jun 13, 2018
Fix #4446: Inline implementation of PF methods into its anonymous class
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A closure that is not a SAM will desugar to something like this in Dotty:
and this in scalac:
The issue with the Dotty desugaring, is that
$anon
will capture a reference to the outer classFoo
that is not neededThe text was updated successfully, but these errors were encountered: