Skip to content

Commit

Permalink
Deprecate integral isWhole
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Apr 8, 2023
1 parent d4f2181 commit 6298da0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -837,7 +837,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// refuses to re-attempt typechecking, and presumes that someone
// else was responsible for issuing the related type error!
fun.setSymbol(NoSymbol)
case _ =>
}
debuglog(s"fallback on implicits: $tree/$resetTree")
// scala/bug#10066 Need to patch the enclosing tree in the context to make translation of Dynamic
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/math/BigInt.scala
Expand Up @@ -278,6 +278,7 @@ final class BigInt private (private var _bigInteger: BigInteger, private val _lo
(shifted.signum != 0) && !(shifted equals BigInt.minusOne)
}

@deprecated("isWhole on an integer type is always true", "2.12.15")
def isWhole: Boolean = true
def underlying: BigInteger = bigInteger

Expand Down
1 change: 1 addition & 0 deletions src/library/scala/runtime/RichInt.scala
Expand Up @@ -31,6 +31,7 @@ final class RichInt(val self: Int) extends AnyVal with ScalaNumberProxy[Int] wit
/** Returns `'''true'''` if this number has no decimal component.
* Always `'''true'''` for `RichInt`.
*/
@deprecated("isWhole on an integer type is always true", "2.12.15")
def isWhole = true

override def isValidInt = true
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/runtime/ScalaNumberProxy.scala
Expand Up @@ -50,6 +50,7 @@ trait ScalaNumberProxy[T] extends Any with ScalaNumericAnyConversions with Typed
@deprecated("use `sign` method instead", since = "2.13.0") def signum: Int = num.signum(self)
}
trait ScalaWholeNumberProxy[T] extends Any with ScalaNumberProxy[T] {
@deprecated("isWhole on an integer type is always true", "2.12.15")
def isWhole = true
}
trait IntegralProxy[T] extends Any with ScalaWholeNumberProxy[T] with RangedProxy[T] {
Expand Down
11 changes: 5 additions & 6 deletions test/files/run/is-valid-num.scala
@@ -1,6 +1,5 @@
/*
* filter: inliner warnings; re-run with
*/
// scalac: -Xlint -Werror
@annotation.nowarn("cat=deprecation&msg=isWhole")
object Test {
def x = BigInt("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
def y = BigDecimal("" + (Short.MaxValue + 1) + ".0")
Expand All @@ -11,7 +10,7 @@ object Test {
def l2 = Int.MinValue.toLong - 1

def main(args: Array[String]): Unit = {
// assert(x.isWhole, x)
assert(x.isWhole, x)
assert(!x.isValidDouble, x)
assert(!x.isValidFloat, x)
assert(!x.isValidLong, x)
Expand Down Expand Up @@ -171,7 +170,7 @@ object Test {

if (!d.isInfinity) {
val bd = BigDecimal(new java.math.BigDecimal(d))
// assert(!bd.isWhole, bd)
assert(!bd.isWhole, bd)
assert(bd.isExactDouble, bd)
assert(bd.isExactFloat == isFloat, bd)
assert(!bd.isValidLong, bd)
Expand Down Expand Up @@ -221,7 +220,7 @@ object Test {
assert(bd.isValidShort == isShort, bd)
assert(bd.isValidByte == isByte, bd)

// assert(bi.isWhole, bi)
assert(bi.isWhole, bi)
assert(bi.isValidDouble == isDouble, bi)
assert(bi.isValidFloat == isFloat, bi)
assert(bi.isValidLong == isLong, bi)
Expand Down
3 changes: 2 additions & 1 deletion test/scalacheck/scala/math/BigIntProperties.scala
Expand Up @@ -5,6 +5,7 @@ import Arbitrary.arbitrary
import org.scalacheck.Prop._
import java.math.BigInteger
import java.lang.Character
import scala.annotation.nowarn
import scala.util.Random

object BigIntProperties extends Properties("BigInt") {
Expand Down Expand Up @@ -95,7 +96,7 @@ object BigIntProperties extends Properties("BigInt") {
property("isValidLong") = forAll { (l: Long) => BigInt(l).isValidLong }
property("isValidLong") = !BigInt("9223372036854775808").isValidLong
property("isValidLong") = !BigInt("-9223372036854775809").isValidLong
property("isWhole") = forAll { (bi: BigInt) => bi.isWhole }
property("isWhole") = forAll { (bi: BigInt) => bi.isWhole: @nowarn }
property("underlying") = forAll(bigInteger) { bi => BigInt(bi).underlying ?= bi }
property("equals") = forAll(bigInteger, bigInteger) { (x, y) => (x == y) ?= (BigInt(x) equals BigInt(y)) }
property("compare") = forAll(bigInteger, bigInteger) { (x, y) => x.compareTo(y) ?= BigInt(x).compare(y) }
Expand Down

0 comments on commit 6298da0

Please sign in to comment.