Work in Progress

We are still in the process of writing the documentation for Scala 3. You can help us to improve the documentation.

Are you searching for the Scala 2 documentation?

Scala 3 Language Reference

Dropped: Class Shadowing


Scala 2 so far allowed patterns like this:

class Base {
  class Ops { ... }

class Sub extends Base {
  class Ops { ... }

Scala 3 rejects this with the error message:

6 |      class Ops {  }
  |            ^
  |class Ops cannot have the same name as class Ops in class Base
  | -- class definitions cannot be overridden

The issue is that the two Ops classes look like one overrides the other, but classes in Scala 2 cannot be overridden. To keep things clean (and its internal operations consistent) the Scala 3 compiler forces you to rename the inner classes so that their names are different.

More details

Contributors to this page: