Skip to content

Invalid override #5052

@allanrenucci

Description

@allanrenucci

Neither scalac nor dotc reports Bar::foo as an invalid override of Foo::foo, even though at runtime, it doesn't override anything

class Foo {
  def test = foo
  protected[this] def foo = 1
}

class Bar extends Foo {
  override private[this] def foo = 2
}

object Test {
  def main(args: Array[String]): Unit = {
    println((new Bar).test)      // prints 1
    println((new Bar: Foo).test) // prints 1
  }
}

Not that modifying Bar as follow fixes the issue:

 class Bar extends Foo {
-  override private[this] def foo = 2
+  override protected[this] def foo = 2
 }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions