refined icon indicating copy to clipboard operation
refined copied to clipboard

Scala 3.2: Comparing NonNegInt with Int gives a compile error

Open longliveenduro opened this issue 3 years ago • 1 comments

If I make an equal comparison on a NonNegInt with Int I get a compile error:

  def mapSignalStrengthUmts(rcspLev: NonNegInt): Option[Int] =
    if rcspLev < 1 then Some(-116) // same as if rcspLev == 0 but this gives a Refined compile error

gives:

Values of types eu.timepit.refined.types.numeric.NonNegInt and Int cannot be compared with == or !=

longliveenduro avatar Nov 08 '22 09:11 longliveenduro

I believe that's expected, as NonNegInt is a intentionally a separate type. One should use .value to unpack. e.g. if rcspLev.value < 1

ivan-klass avatar Jun 05 '24 08:06 ivan-klass