From 6298da00727e516131fdef5a029b2fb68bf3e1ff Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 8 Apr 2023 08:51:01 -0700 Subject: [PATCH] Deprecate integral isWhole --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 1 - src/library/scala/math/BigInt.scala | 1 + src/library/scala/runtime/RichInt.scala | 1 + src/library/scala/runtime/ScalaNumberProxy.scala | 1 + test/files/run/is-valid-num.scala | 11 +++++------ test/scalacheck/scala/math/BigIntProperties.scala | 3 ++- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index cdec1bc9537f..59cec79257f0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -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 diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index c48bab4445ee..f4f248debde2 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -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 diff --git a/src/library/scala/runtime/RichInt.scala b/src/library/scala/runtime/RichInt.scala index 5538ba700ff1..fbe9aecd1b70 100644 --- a/src/library/scala/runtime/RichInt.scala +++ b/src/library/scala/runtime/RichInt.scala @@ -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 diff --git a/src/library/scala/runtime/ScalaNumberProxy.scala b/src/library/scala/runtime/ScalaNumberProxy.scala index f5afdf0225ec..cf3e21460ca7 100644 --- a/src/library/scala/runtime/ScalaNumberProxy.scala +++ b/src/library/scala/runtime/ScalaNumberProxy.scala @@ -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] { diff --git a/test/files/run/is-valid-num.scala b/test/files/run/is-valid-num.scala index eb364e055580..ef2388f8baa3 100644 --- a/test/files/run/is-valid-num.scala +++ b/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") @@ -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) @@ -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) @@ -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) diff --git a/test/scalacheck/scala/math/BigIntProperties.scala b/test/scalacheck/scala/math/BigIntProperties.scala index d036719b368f..a5107c4bf425 100644 --- a/test/scalacheck/scala/math/BigIntProperties.scala +++ b/test/scalacheck/scala/math/BigIntProperties.scala @@ -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") { @@ -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) }