Skip to content

Commit ae41466

Browse files
committed
Dotty compat: move Numeric#Ops to Numeric.Ops
Dotty does not allow name clashes of inner classes, and the inner class is polluting Numeric's interface anyway. Note that a similar case can be made for Ordering#Ops. Also note that this breaks source compatibility. Fixes scala/scala-dev#156
1 parent efb74b7 commit ae41466

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/library/scala/math/Numeric.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ object Numeric {
189189

190190
implicit object DoubleIsFractional extends DoubleIsFractional with Ordering.DoubleOrdering
191191
object DoubleAsIfIntegral extends DoubleAsIfIntegral with Ordering.DoubleOrdering
192+
193+
class Ops[T](self: Numeric[T], lhs: T) {
194+
def +(rhs: T): T = self.plus(lhs, rhs)
195+
def -(rhs: T): T = self.minus(lhs, rhs)
196+
def *(rhs: T): T = self.times(lhs, rhs)
197+
def unary_-(): T = self.negate(lhs)
198+
def abs(): T = self.abs(lhs)
199+
def signum(): Int = self.signum(lhs)
200+
def toInt(): Int = self.toInt(lhs)
201+
def toLong(): Long = self.toLong(lhs)
202+
def toFloat(): Float = self.toFloat(lhs)
203+
def toDouble(): Double = self.toDouble(lhs)
204+
}
192205
}
193206

194207
trait Numeric[T] extends Ordering[T] {
@@ -211,17 +224,5 @@ trait Numeric[T] extends Ordering[T] {
211224
else if (gt(x, zero)) 1
212225
else 0
213226

214-
class Ops(lhs: T) {
215-
def +(rhs: T) = plus(lhs, rhs)
216-
def -(rhs: T) = minus(lhs, rhs)
217-
def *(rhs: T) = times(lhs, rhs)
218-
def unary_-() = negate(lhs)
219-
def abs(): T = Numeric.this.abs(lhs)
220-
def signum(): Int = Numeric.this.signum(lhs)
221-
def toInt(): Int = Numeric.this.toInt(lhs)
222-
def toLong(): Long = Numeric.this.toLong(lhs)
223-
def toFloat(): Float = Numeric.this.toFloat(lhs)
224-
def toDouble(): Double = Numeric.this.toDouble(lhs)
225-
}
226-
implicit def mkNumericOps(lhs: T): Ops = new Ops(lhs)
227+
implicit def mkNumericOps(lhs: T): Numeric.Ops[T] = new Numeric.Ops(this, lhs)
227228
}

0 commit comments

Comments
 (0)