I have a function similar to this one, matching on outputSize
:
def size(
outputSize: Int | Option[Int] | (Option[Int], Option[Int]) | (Int, Int)
): (Option[Int], Option[Int]) = outputSize match
case x: Int => (Some(x), Some(x))
case x: Option[Int] => (x, x)
case (h, w): (Int, Int) => (Some(h), Some(w))
case (h, w): (Option[Int], Option[Int]) => (h, w)
After upgrading to Scala 3.3, the last two cases trigger a warning:
Type ascriptions after patterns other than:
* variable pattern, e.g. `case x: String =>`
* number literal pattern, e.g. `case 10.5: Double =>`
are no longer supported. Remove the type ascription or move it to a separate variable pattern.
The first can be solved by moving the type ascription into the tuple match:
case (h: Int, w: Int) => (Some(h), Some(w))
But that doesn’t work for the second one due to type erasure:
case (h: Option[Int], w: Option[Int]) => (h, w)
the type test for Option[Int] cannot be checked at runtime because its type arguments can't be determined from Any
Perhaps I’m missing the obvious here, but I’m having difficulties matching on that latest case in Scala 3.3.0 without a warning. Any ideas?