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

final inner class not final in bytecode #7151

Closed
scabug opened this issue Feb 19, 2013 · 8 comments
Closed

final inner class not final in bytecode #7151

scabug opened this issue Feb 19, 2013 · 8 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 19, 2013

This works fine in 2.9.{1,2}:

Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> abstract class Filter() {if (!java.lang.reflect.Modifier.isFinal(getClass().getModifiers())) throw new IllegalStateException("Class " +getClass().getName() + " must be final");}
defined class Filter

scala> final case class Moo() extends Filter()
defined class Moo

scala> Moo()
res0: Moo = Moo()

scala> new Moo()
res1: Moo = Moo()

In Scala-2.10.0 and 2.10.1-RC1 the case class isn't recognized as final anymore:

Welcome to Scala version 2.10.1-RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> abstract class Filter() {if (!java.lang.reflect.Modifier.isFinal(getClass().getModifiers())) throw new IllegalStateException("Class " +getClass().getName() + " must be final");}
defined class Filter

scala> final case class Moo() extends Filter()
defined class Moo

scala> Moo()
java.lang.IllegalStateException: Class Moo must be final
        at Filter.<init>(<console>:7)
        at Moo.<init>(<console>:8)
        at .<init>(<console>:11)
        at .<clinit>(<console>)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
        at $print(<console>)
...
...
scala> new Moo()
java.lang.IllegalStateException: Class Moo must be final
        at Filter.<init>(<console>:7)
        at Moo.<init>(<console>:8)
        at .<init>(<console>:11)
        at .<clinit>(<console>)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
        at $print(<console>)
@scabug
Copy link
Author

scabug commented Feb 19, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7151?orig=1
Reporter: Andreas Joseph Krogh (andreak)
Affected Versions: 2.10.0, 2.10.1-RC1, 2.10.1
See #5676

@scabug
Copy link
Author

scabug commented Jun 6, 2013

@retronym said:
This is limited to inner classes:

import java.lang.reflect.Modifier.isFinal

object Test {
  final case class InnerCase()
  final class InnerNonCase()

  def main(args: Array[String]) {
    def checkFinal(clazz: Class[_]) =
      println(s"${clazz} isFinal = ${isFinal(clazz.getModifiers())}")
    checkFinal(classOf[InnerCase])
    checkFinal(classOf[InnerNonCase])
    checkFinal(classOf[TopLevelCase])
    checkFinal(classOf[TopLevelNonCase])
  }
}

final case class TopLevelCase()
final case class TopLevelNonCase()
qbin/scalac sandbox/t7151.scala && qbin/scala -nc Test
class Test$InnerCase isFinal = false
class Test$InnerNonCase isFinal = false
class TopLevelCase isFinal = true
class TopLevelNonCase isFinal = true

It regressed in scala/scala@18efded

@scabug
Copy link
Author

scabug commented Jun 6, 2013

@retronym said:
scala/scala#2635

@scabug
Copy link
Author

scabug commented Jun 6, 2013

Andreas Joseph Krogh (andreak) said:

Any chance of fixing this in 10.0.2?

@scabug
Copy link
Author

scabug commented Jun 6, 2013

@retronym said:
We'll see what we can do.

@scabug scabug closed this as completed Jun 19, 2013
@scabug
Copy link
Author

scabug commented Sep 17, 2013

Andreas Joseph Krogh (andreak) said (edited on Sep 17, 2013 7:19:27 AM UTC):
Will this get backported to 2.10.3?

@scabug
Copy link
Author

scabug commented Sep 17, 2013

@retronym said:
scala/scala#2636 (comment) binary compatibility questions made us do this for 2.11 only

@scabug
Copy link
Author

scabug commented Sep 17, 2013

Andreas Joseph Krogh (andreak) said:
Ok, thanks.

@scabug scabug added this to the 2.11.0-M4 milestone Apr 7, 2017
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