You need space between = and - , or you can wrap -1 in parentheses, otherwise the compiler gets confused. This is because =- is a valid method name, so the compiler cannot determine whether you assign a value to a named parameter or call a method call.
therefore this gives an error:
val f = Fraction(numerator=-1, denominator=2)
but it normal:
val f = Fraction(numerator = -1, denominator = 2)
and so on:
val f = Fraction(numerator=(-1), denominator=2)
source share