Skip to content

Unsoundness when inheriting conflicting type parameters #10735

Open
@odersky

Description

@odersky

The following program compiles under 2.12.3 but gives a ClassCastException at runtime.

import java.util.Comparator

trait Trait1[T] { def foo(arg: Comparator[T]): String }

trait Trait2[T] extends Trait1[T] { def foo(arg: Comparator[String]): Int = 0 }

class Class1 extends Trait2[String] { }

object Test {
  def main(args: Array[String]): Unit = {
    val c = new Class1
    c.foo(Ordering[String])
    val t: Trait1[String] = c
    val x: String = t.foo(Ordering[String])
  }
}

This is an adaptation of the example in Scala SI 4731.scala. The issue is in response to scala/scala3#3989. The fix for #3989 broke the test case pos/t4731.scala, and investigation showed that the flagged inheritance is unsound.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions