How to make inline match and default arguments work together in Scala 3?

Viewed 55

I have the following, combining inline match and default argument:

inline def func(myArg: (Int | String) = 0) =
  inline myArg match
    case i: Int => ()
    case s: String => ()

It works fine when called so that the default value is not used:

// works fine
func(1)

However, when the value is used, it fails to compile:

// fails
func()

with

[error]     |cannot reduce inline match with
[error]     | scrutinee:  myArg$proxy1 : (myArg$proxy1 : (Int | String) @uncheckedVariance)
[error]     | patterns :  case i @ _:Int
[error]     |             case s @ _:String

Apparently the default value is a method that is not inlined. Is there a way around this?

0 Answers
Related