Skip to content
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

NumericRange.max / NumericRange.min throw with custom integral types #10086

Closed
scabug opened this issue Dec 2, 2016 · 2 comments
Closed

NumericRange.max / NumericRange.min throw with custom integral types #10086

scabug opened this issue Dec 2, 2016 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Dec 2, 2016

The following throws:

object Test {

  import scala.collection.immutable.NumericRange

  case class A(v: Int)

  implicit object aIsIntegral extends scala.math.Integral[A] {
    def compare(x: A, y: A): Int = x.v - y.v
    def fromInt(x: Int): A = A(x)
    def minus(x: A, y: A): A = A(x.v - y.v)
    def negate(x: A): A = A(-x.v)
    def plus(x: A, y: A): A = A(x.v + y.v)
    def times(x: A, y: A): A = A(x.v * x.v)
    def quot(x: A, y: A): A = A(x.v / y.v)
    def rem(x: A, y: A): A = A(x.v % y.v)
    def toDouble(x: A): Double = x.v.toDouble
    def toFloat(x: A): Float = x.v.toFloat
    def toInt(x: A): Int = x.v
    def toLong(x: A): Long = x.v.toLong
  }

  def main(args: Array[String]): Unit = {
    val r = NumericRange(A(1), A(10), A(1))

    println(r)
    // NumericRange(A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9))
    // As expected.

    println(r.max)
    // java.util.NoSuchElementException: key not found: Test$aIsIntegral$@1a0e35d3
    // 	at scala.collection.MapLike$class.default(MapLike.scala:228)
    // 	at scala.collection.AbstractMap.default(Map.scala:58)
    // 	at scala.collection.MapLike$class.apply(MapLike.scala:141)
    // 	at scala.collection.AbstractMap.apply(Map.scala:58)
    // 	at scala.collection.immutable.NumericRange.max(NumericRange.scala:137)
    // 	at Test$.main(Test.scala:26)
    // 	at Test.main(Test.scala)
    // 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    // 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    // 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    // 	at java.lang.reflect.Method.invoke(Method.java:498)

    // Expected A(9)
  }
}
@scabug
Copy link
Author

scabug commented Dec 2, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10086?orig=1
Reporter: @gzm0

@scabug
Copy link
Author

scabug commented Dec 2, 2016

@som-snytt said (edited on Dec 2, 2016 11:41:52 PM UTC):
WIP scala/scala#5575

@scabug scabug closed this as completed Dec 12, 2016
@scabug scabug added this to the 2.11.9 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants