Skip to content

Fun with overrides #1240

Closed
Closed
@DarkDimius

Description

@DarkDimius

Simple example. Fails in scalac\javac, succeeds in Dotty.

class A[T] {
  def foo(x: T): T
  def foo(x: Int): Int
  new A[Int]().foo(1) // what foo should be called? scalac/javac issue an error here. Dotty calls the lexically-first one
}

More complicated example:

abstract class A {
  type C[X]
  def foo[B](x: C[B]): C[B]       = {println("A.C"); x}
  def foo[B](x: List[B]): List[B] = {println("A.List"); x}
  def give[X]: C[X]
}

class B extends A {
  type C[X] = List[X]
  override def give[X] = Nil
  override def foo[B](x: C[B]): C[B] =  {println("B.C"); x} 
                                           // which method is overriden? 
                                           // should any bridges be generated?
  val a: A = this
  a.foo(a.give[Int]) // what method should be called here in runtime?
}

In this example neither scalac nor dotty generate bridges.
Ping @retronym @adriaanm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions