Closed
Description
Compiler version
3.3.1, 3.4.0-RC1
Minimized example
object Example {
class Bar(foo: Foo)
class Foo
given Foo = Foo()
given bar(foo: Foo): Bar = Bar(foo)
}
Output Error/Warning message
[error] -- [E040] Syntax Error: /.../Example.scala:11:11
[error] 11 | given bar(foo: Foo): Bar = Bar(foo)
[error] | ^
[error] | ':' expected, but '(' found
[error] -- [E067] Syntax Error: /.../Example.scala:11:8
[error] 11 | given bar(foo: Foo): Bar = Bar(foo)
[error] | ^
[error] |Declaration of given instance bar not allowed here: only classes can have declared but undefined members
Why this Error/Warning was not helpful
I intended to write given bar(using foo: Foo): Bar = Bar(foo)
but forgot the using
keyword.
If I wasn't already familiar with these errors it would be hard to figure out what's wrong. The second error can be quite misleading if you don't pay attention to the reason ("only classes can have declared but undefined members"). And it's too easy to dismiss that reason because my given
does appear to have a defined body.
Suggested improvement
Ideally I expect an error saying that given
-s can't have non-implicit arguments, and that I need a using
keyword. Or anything that comes closer to that than the status quo really.