You are seeing a problem with semicolon inference, due to the use of a postfix operator (product
):
// Error
val n = (x: Int) => (1 to x) product
println(n(5))
// OK - explicit semicolon
val n = (x: Int) => (1 to x) product;
println(n(5))
// OK - explicit method call instead of postfix - I prefer this one
val n = (x: Int) => (1 to x).product
println(n(5))
// OK - note the newline, but I wouldn't recommend this solution!
val n = (x: Int) => (1 to x) product
println(n(5))
Essentially, Scala gets confused as to where an expression ends, so you need to be a little more explicit, one way or another.
Depending on compiler settings, this feature may be disabled by default - see Scala's "postfix ops" and SIP-18: Modularizing Language Features