Skip to content

Overload in Scala 2 treated as Override in Dotty #4781

Closed
@allanrenucci

Description

@allanrenucci
class A
class B extends A

class Map[T] { def foo(x: T): A = new A }
// This is an overload and not an override
class AnyRefMap[T <: AnyRef] extends Map[T] { def foo(y: T with AnyRef): B = new B }

object Test {
  (new AnyRefMap[String]).foo("Hello") // B
  (new AnyRefMap[String]: Map[String]).foo("Hello") // A
}
-- Error: tests/allan/Test.scala:32:50 -----------------------------------------
32 |class AnyRefMap[T <: AnyRef] extends Map[T] { def foo(y: T with AnyRef): B = new B }
   |                                                  ^
   |       error overriding method foo in class Map of type (x: T): A;
   |         method foo of type (y: T & AnyRef): B needs `override' modifier
one error found

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions