Hey,
Today I’ve started to learn about the inline in scala, and figured out something that looks peculiar to me in regard to inline conditions.
Having the code below, I’ve got an error when tried the inline condition call on a variable anotherFalse of type Boolean, which was normal.
But when a variable of Int type is passed to the inline function with and inline pattern match I haven’t got a compilation error and, moreover, the result is strange.
Value 2 (Int) lead to the result “many” ![]()
Is normal this behavior?
Thanks
inline def condition(x: Boolean): String = inline if x then "true" else "false"
inline val aFalse = false
val cFalse = condition(aFalse)
// val anotherFalse = false
// val cFalse = condition(anotherFalse) // this one gives a compile-time error as expected
inline def pMatch(x: Int): String = inline x match {
case 0 => "zero"
case 1 => "one"
case 2 => "two"
case _ => "many"
}
inline val aOne = 1
val pOne = pMatch(aOne) // works fine because aOne is inline
val aTwo = 2
val pTwo = pMatch(
aTwo
) // I expected a compile-time error here as it is the case for Boolean, but it compiles fine and pTwo is "many" :frowning:
@main def main() = {
println(pOne)
println(pTwo) // "many"
}