Skip to content

Commit

Permalink
Simplify check for float conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Apr 10, 2023
1 parent 8ba14ae commit b84df96
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/compiler/scala/tools/nsc/Reporting.scala
Expand Up @@ -341,10 +341,7 @@ object Reporting {
private val insertDash = "(?=[A-Z][a-z])".r

val all: mutable.Map[String, WarningCategory] = mutable.Map.empty
private def add(c: WarningCategory): Unit = {
require(!all.contains(c.name), s"lint '${c.name}' added twice")
all addOne (c.name, c)
}
private def add(c: WarningCategory): Unit = all.put(c.name, c).ensuring(_.isEmpty, s"lint '${c.name}' added twice")

object Deprecation extends WarningCategory; add(Deprecation)

Expand Down
8 changes: 2 additions & 6 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -5290,12 +5290,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// xml member to StringContext, which in turn has an unapply[Seq] method)

def checkDubiousAdaptation(sel: Tree): Unit = if (!isPastTyper && settings.lintNumericMethods) {
def richlyFloat = Set("isNaN", "isInfinity", "isInfinite", "isFinite", "isPosInfinity", "isNegInfinity", "round", "ceil", "floor")
val dubious = ScalaIntegralValueClasses(qualTp.typeSymbol) && richlyFloat(name.decoded) && (
sel.symbol.owner.eq(BoxedFloatClass)
||
sel.symbol.owner.eq(rootMirror.getClassIfDefined("scala.runtime.RichFloat"))
)
val dubious = ScalaIntegralValueClasses(qualTp.typeSymbol) && (
sel.symbol.owner.eq(BoxedFloatClass) || sel.symbol.owner.eq(RichFloatClass))
if (dubious)
context.warning(tree.pos, s"dubious usage of ${sel.symbol} with integer value", WarningCategory.LintNumericMethods)
}
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/Definitions.scala
Expand Up @@ -104,6 +104,7 @@ trait Definitions extends api.StandardDefinitions {
lazy val lazyHolders = symbolsMap(ScalaValueClasses, x => getClassIfDefined("scala.runtime.Lazy" + x))
lazy val LazyRefClass = getClassIfDefined("scala.runtime.LazyRef")
lazy val LazyUnitClass = getClassIfDefined("scala.runtime.LazyUnit")
lazy val RichFloatClass = getClassIfDefined("scala.runtime.RichFloat")

lazy val allRefClasses: Set[Symbol] = {
refClass.values.toSet ++ volatileRefClass.values.toSet ++ Set(VolatileObjectRefClass, ObjectRefClass)
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
Expand Up @@ -506,6 +506,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.lazyHolders
definitions.LazyRefClass
definitions.LazyUnitClass
definitions.RichFloatClass
definitions.allRefClasses
definitions.UnitClass
definitions.ByteClass
Expand Down

0 comments on commit b84df96

Please sign in to comment.