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

Range.sum ignores Numeric argument #7443

Closed
scabug opened this issue May 1, 2013 · 2 comments
Closed

Range.sum ignores Numeric argument #7443

scabug opened this issue May 1, 2013 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 1, 2013

see code

  final override def sum[B >: Int](implicit num: Numeric[B]): Int = {
    if (isEmpty) 0
    else if (numRangeElements == 1) head
    else (numRangeElements.toLong * (head + last) / 2).toInt
  }

test that show that such implementation is wrong

scala>  object mynum extends Numeric[Int] { 
     |   // Members declared in scala.math.Numeric
     |   def fromInt(x: Int): Int = ???
     |   def minus(x: Int,y: Int): Int = ???
     |   def negate(x: Int): Int = ???
     |   def plus(x: Int,y: Int): Int = ???
     |   def times(x: Int,y: Int): Int = ???
     |   def toDouble(x: Int): Double = ???
     |   def toFloat(x: Int): Float = ???
     |   def toInt(x: Int): Int = ???
     |   def toLong(x: Int): Long = ???
     |   
     |   // Members declared in scala.math.Ordering
     |   def compare(x: Int,y: Int): Int = ???
     | }
defined module mynum

scala> (1 to 100).sum(mynum)
res0: Int = 5050

This test should throw scala.NotImplementedError

@scabug
Copy link
Author

scabug commented May 1, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7443?orig=1
Reporter: @DarkDimius
Affected Versions: 2.10.1, 2.10.3

@scabug
Copy link
Author

scabug commented Jan 10, 2014

@adriaanm said:
scala/scala#3124

@scabug scabug closed this as completed Jan 10, 2014
@scabug scabug added this to the 2.11.0-M8 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