Skip to content

dotc makes every single object extend java.io.Serializable, which it shouldn't. #9596

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

Closed
sjrd opened this issue Aug 19, 2020 · 1 comment
Closed

Comments

@sjrd
Copy link
Member

sjrd commented Aug 19, 2020

Minimized code

object Test

Output

sbt:dotty> dotc -Xprint:typer tests/run/hello.scala
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[info] running (fork) dotty.tools.dotc.Main -classpath C:\Users\sjrdo\AppData\Local\Coursier\cache\v1\https\repo1.maven.org\maven2\org\scala-lang\scala-library\2.13.3\scala-library-2.13.3.jar;C:\Users\sjrdo\Documents\Projets\dotty\library\..\out\bootstrap\dotty-library-bootstrapped\scala-0.27\dotty-library_0.27-0.27.0-bin-SNAPSHOT.jar -Xprint:typer tests/run/hello.scala
result of tests\run\hello.scala after typer:
package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object(), _root_.scala.Serializable {
    this: Test.type =>
  }
}
[success] Total time: 4 s, completed 19 ao¹t 2020 18:11:54
$ javap -cp . Test$
Compiled from "hello.scala"
public final class Test$ implements java.io.Serializable {
  public static final Test$ MODULE$;
  public static {};
}

Expectation

I expect Test not to extend java.io.Serializable. It was not asked for in the source code.

scalac does not make objects java.io.Serializable like that.

This is very problematic for Scala.js because JS objects cannot extend java.io.Serializable, which is a Scala class.

@sjrd sjrd added the itype:bug label Aug 19, 2020
sjrd added a commit to dotty-staging/dotty that referenced this issue Aug 19, 2020
sjrd added a commit to dotty-staging/dotty that referenced this issue Aug 19, 2020
sjrd added a commit to dotty-staging/dotty that referenced this issue Aug 19, 2020
sjrd added a commit to dotty-staging/dotty that referenced this issue Aug 20, 2020
smarter added a commit that referenced this issue Aug 20, 2020
…ts-in-backend

Mitigate #9596 for SJS: Make objects serializable only in the JVM back-end.
@smarter
Copy link
Member

smarter commented Aug 20, 2020

#9600 fixed the scala.js issue, closing since I think having objects extend Serializable in the JVM backend is legitimate (cf the comment added in the PR)

@smarter smarter closed this as completed Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants