This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Compiler optimization bug?

3 replies
Alan Burlison
Joined: 2011-08-26,
User offline. Last seen 42 years 45 weeks ago.

----------
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
$

Alan Burlison
Joined: 2011-08-26,
User offline. Last seen 42 years 45 weeks ago.
Re: Compiler optimization bug?

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

Alex Cruise
Joined: 2008-12-17,
User offline. Last seen 2 years 26 weeks ago.
Re: Re: Compiler optimization bug?
On Fri, Dec 16, 2011 at 9:12 AM, Alan Burlison <alan.burlison@gmail.com> wrote:
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
Alan Burlison
Joined: 2011-08-26,
User offline. Last seen 42 years 45 weeks ago.
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.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland