Skip to content

Unsoundness when inheriting conflicting type parameters #10735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
odersky opened this issue Feb 19, 2018 · 1 comment
Open

Unsoundness when inheriting conflicting type parameters #10735

odersky opened this issue Feb 19, 2018 · 1 comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

Comments

@odersky
Copy link

odersky commented Feb 19, 2018

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.

@Atry
Copy link

Atry commented Feb 21, 2018

Currently I created some conflicting refinement type intentionally, in order to mimic the type variance behavior of intersection types.

Stricter type checking on conflicting types may be sound, however it will break existing code.

I hope this bug will not be fixed until introducing true intersection types.

@smarter smarter added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

3 participants