Skip to content

Java interop : can't compare generic arrays #8615

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

Closed
rjolly opened this issue Mar 26, 2020 · 0 comments
Closed

Java interop : can't compare generic arrays #8615

rjolly opened this issue Mar 26, 2020 · 0 comments
Assignees

Comments

@rjolly
Copy link
Contributor

rjolly commented Mar 26, 2020

minimized code

class ArrayOrdering[N] extends scala.math.Ordering[Array[N]] {
  def compare(x: Array[N], y: Array[N]) = ???
}

Compilation output

  def compare(x: Array[N], y: Array[N]) = ???
      ^
error overriding method compare in trait Comparator of type (x$0: Array[N], x$1: Array[N]): Int;
  method compare of type (x: Array[N], y: Array[N]): Int has incompatible type
(Note that Scala's and Java's representation of this type differs)

expectation

Should work, as in the specialized case:

class ArrayIntOrdering extends scala.math.Ordering[Array[Int]] {
  def compare(x: Array[Int], y: Array[Int]) = ??? // works fine
}

workaround

trait Ordering[T] extends scala.math.Ordering[T] {
  def compare(x: T, y: T) = compares(x, y)
  def compares(x: T, y: T): Int
}
class ArrayOrdering[N] extends Ordering[Array[N]] {
  def compares(x: Array[N], y: Array[N]) = ??? // works fine
}
smarter added a commit to smarter/dotty that referenced this issue Aug 19, 2020
This appears to already be fixed.
rjolly added a commit to rjolly/scas that referenced this issue Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants