Skip to content

Unsoundness due to invalid inheritance being permitted #5817

Closed
@abgruszecki

Description

@abgruszecki
object Test {
  trait A[+X] { def x: X }
  class B[+X](val x: X) extends A[X]
  class C[+X](x: Any) extends B[Any](x) with A[X]

  def get(a: A[Int]): Int = a.x
  get(new C[Int]("foo")) // class cast exception: String is not Int
}

Note that we previously came to the conclusion that we do not want to prevent inheritance like C in general: #3989.

The likely fix would be to require C to override B#x - this is precisely what Scalac does.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions