Closed
Description
Compiler version
3.3.1
Minimized example
case class Foo(a: Int, b: Int)
object Bar:
Foo(1 2)
// Or
Foo(
a = 1
b = 2
)
Output Error/Warning message
-- [E040] Syntax Error: /Users/hvanrijswijk1/ws/explore/Foo.scala:4:8 ----------
4 | Foo(1 2)
| ^
| ')' expected, but integer literal found
When using named arguments the error is even more confusing:
-- [E018] Syntax Error: /Users/hvanrijswijk1/ws/explore/Foo.scala:8:6 ----------
8 | b = 2
| ^
| expression expected but = found
|
| longer explanation available when compiling with `-explain`
-- [E008] Not Found Error: /Users/hvanrijswijk1/ws/explore/Foo.scala:8:4 -------
7 | a = 1
8 | b = 2
| ^
| value b is not a member of Int.
| Note that `b` is treated as an infix operator in Scala 3.
| If you do not want that, insert a `;` or empty line in front
| or drop any spaces behind the operator.
Why this Error/Warning was not helpful
Following the compiler suggestion and adding a )
would just lead to another compile error, as it is expecting more arguments. It's much more likely that a ,
is missing.
For named arguments the first error is similar to the first when not using named arguments, but the second one is more confusing, as the suggestion of a ;
does not work, nor does adding an empty line (it is already there!)
Suggested improvement
Something similar to what TypeScript does:
foo(1 2)
Error:
',' expected.
This should also work for named arguments:
Foo(
a = 1
b = 2
)