Skip to content

Infer result type using type of overridden method, if any (and not using the rhs) #7212

Closed
scala/scala
#9891
@scabug

Description

@scabug

An old email for which I never opened a ticket. It is undesirable that implementing an abstract method with an implementation like sys.error("no implementation yet") should force all subclasses to throw an exception. It is extremely unlikely anyone would want this "most specific type" to be inferred as the return type of a method for which less exceptional return type is already known (i.e. I'm not talking about def ??? which is born in the same location as the exception; I'm talking about any method for which there is an abstract or concrete implementation in a superclass.)

In the following, how does one define foo in class B such that:

 1) class A's foo definitions can be swapped without modifying B
 2) class C compiles

Can you? I can't.  But I should be able to.

  class A {
    def foo = new A
    // def foo = new B
  }

  class B extends A {
    override def foo = sys.error("")
  }

  class C extends B {
    override def foo = new C
  }

Metadata

Metadata

Assignees

Labels

fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)has PRinfer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions