- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Compiler optimization bug?
Thu, 2011-12-15, 14:32
----------
import java.io.{File}
abstract sealed trait Path {
val path: String
val name: String
}
case class ExternalPath(path: String) extends File(path) with Path {
override lazy val name: String = getName
}
----------
$ scalac -version
Scala compiler version 2.10.0.dev-1302-g6a33a20 -- Copyright 2002-2011,
LAMP/EPFL
$ scala z.scala
$
$ scala -optimize z.scala
/tmp/z.scala:6: error: overriding value path in trait Path of type String;
variable path in class File of type String has weaker access
privileges; it should not be private
case class ExternalPath(path: String) extends File(path) with Path {
^
one error found
$
Fri, 2011-12-16, 20:01
#2
Re: Re: Compiler optimization bug?
On Fri, Dec 16, 2011 at 9:12 AM, Alan Burlison <alan.burlison@gmail.com> wrote:
The difference in behaviour might actually be a bug, and you might already know this, but for the benefit of others who might be reading:
You should never declare abstract vals in traits unless you know exactly what you're doing (I usually don't!)
Instead, declare them as defs, and the case class's generated accessors will "implement" them nicely.
-0xe1a
As I haven't heard to the contrary, I'm assuming this is a bug. Filed as https://issues.scala-lang.org/
browse/SI-5322
The difference in behaviour might actually be a bug, and you might already know this, but for the benefit of others who might be reading:
You should never declare abstract vals in traits unless you know exactly what you're doing (I usually don't!)
Instead, declare them as defs, and the case class's generated accessors will "implement" them nicely.
-0xe1a
Fri, 2011-12-16, 23:01
#3
Re: Re: Compiler optimization bug?
On 16/12/2011 18:55, Alex Cruise wrote:
> The difference in behaviour might actually be a bug, and you might already
> know this, but for the benefit of others who might be reading:
>
> You should never declare abstract vals in traits unless you know exactly
> what you're doing (I usually don't!)
>
> Instead, declare them as defs, and the case class's generated accessors
> will "implement" them nicely.
In this case the code compiles fine unless optimization is turned on,
which suggests it's an optimiser bug. However, thanks for the warning
about abstracts in traits.
As I haven't heard to the contrary, I'm assuming this is a bug. Filed
as https://issues.scala-lang.org/browse/SI-5322