Aladdin - Scala Bugtracking
[#95] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Matthias Martin fixed 2003-08-28 12:43:04.0
subject Extending AnyVal, AnyRef, etc.
code
class C extends AnyVal;
what happened
The program compiles.
what expected It should not be possible to inherit from AnyVal. I think we should enforce that all classes written in Scala are subclasses of scala.AnyRef. Alternatively, we could also require that all classes are either subclasses of scala.Object or they subclass a Java class.
[back to overview]
Changes of this bug report
Matthias  edited on  2003-08-28 12:45:10.0
Martin  edited on  2003-08-28 14:06:50.0
Matthias  edited on  2003-09-01 01:13:07.0
I just re-opened the bug again, because the current fix is not sufficient. Currently, AnyVal is declared to be sealed. One implication of this is that it's not possible to subclass AnyVal. But it's still possible to subclass existing value classes like Byte, Short, Int, etc. These classes should be either final or at least sealed. Otherwise it's quite easy to crash the compiler. Here is an example:
class T extends Unit;
This yields the following exception:
{
  scala.Unit();
  scala.runtime.RunTime.box()
}
Exception in thread "main" java.lang.AssertionError
        at scalac.transformer.AddConstructors.transform(AddConstructors.java:211)
        at scalac.ast.Transformer.transform(Transformer.java:276)
        at scalac.ast.Transformer.apply(Transformer.java:67)
        at scalac.transformer.AddConstructorsPhase.apply(AddConstructorsPhase.java:42)
        at scalac.Global.compile(Global.java:266)
        at scalac.Global.compile(Global.java:245)
        at scalac.Main.main(Main.java:32)
Martin  edited on  2003-09-02 18:57:31.0