Skip to content
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

scalac should respect JEP 409 "Sealed Classes" at compile time #12171

Closed
xuwei-k opened this issue Sep 30, 2020 · 4 comments · Fixed by scala/scala#10105 or scala/scala#10348
Closed

scalac should respect JEP 409 "Sealed Classes" at compile time #12171

xuwei-k opened this issue Sep 30, 2020 · 4 comments · Fixed by scala/scala#10105 or scala/scala#10348

Comments

@xuwei-k
Copy link

xuwei-k commented Sep 30, 2020

reproduction steps

java --version

openjdk 15 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

A.java

package foo;

public sealed class A{}

final class B extends A{}

Main.scala

package foo

class C extends A

object Main {
  def main(args: Array[String]): Unit = {
    new C
  }
}

build.sbt

javacOptions ++= Seq("--enable-preview", "--release", "15")
scalaVersion := "2.13.3"
// https://github.com/scala/bug/issues/12159
compileOrder := CompileOrder.JavaThenScala

project/build.properties

sbt.version=1.3.13

problem

runtime error 😢

sbt -J--enable-preview run

[info] running foo.Main 
[error] (run-main-0) java.lang.IncompatibleClassChangeError: class foo.C cannot inherit from sealed class foo.A
[error] java.lang.IncompatibleClassChangeError: class foo.C cannot inherit from sealed class foo.A
[error] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[error] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
[error] 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
[error] 	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:514)
[error] 	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:422)
[error] 	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:416)
[error] 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
[error] 	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:415)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1
@xuwei-k
Copy link
Author

xuwei-k commented Sep 30, 2020

scala/scala#9228

@SethTisue
Copy link
Member

it would make sense to tackle this and #12159 together

@SethTisue SethTisue modified the milestones: 2.13.5, 2.13.6 Feb 9, 2021
@SethTisue
Copy link
Member

Volunteer to pick up scala/scala#9228 and run with it?

@dwijnand dwijnand modified the milestones: 2.13.6, 2.13.7 May 10, 2021
@SethTisue SethTisue changed the title scalac should be reject in compile time for extends JEP 360 "Sealed Classes" scalac should respect JEP 360 "Sealed Classes" at compile time Oct 16, 2021
@SethTisue SethTisue modified the milestones: 2.13.7, 2.13.8 Oct 21, 2021
@SethTisue SethTisue modified the milestones: 2.13.8, 2.13.9 Dec 15, 2021
@SethTisue SethTisue modified the milestones: 2.13.9, 2.13.10, Backlog Apr 25, 2022
@SethTisue SethTisue modified the milestones: Backlog, 2.13.9 Aug 10, 2022
@SethTisue SethTisue changed the title scalac should respect JEP 360 "Sealed Classes" at compile time scalac should respect JEP 409 "Sealed Classes" at compile time Aug 10, 2022
@SethTisue
Copy link
Member

Note that on JDK 17, --enable-preview isn't necessary to use sealed.

The non-preview version of the JEP is at https://openjdk.org/jeps/409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment