unhelpful error message when overloading apply without return type
See original GitHub issuedotty
:
scala> case class Foo[T](x: T); object Foo { def apply[T]() = Foo(null.asInstanceOf[T]) }
-- Error: <console> ----------------------------------------------------------------------
6 |case class Foo[T](x: T); object Foo { def apply[T]() = Foo(null.asInstanceOf[T]) }
| ^^^
| object Foo does not take parameters
The solution is to write def apply[T](): Foo[T]
but good luck figuring that out from our error message, contrast with scalac
:
scala> case class Foo[T](x: T); object Foo { def apply[T]() = Foo(null.asInstanceOf[T]) }
<console>:15: error: overloaded method apply needs result type
case class Foo[T](x: T); object Foo { def apply[T]() = Foo(null.asInstanceOf[T]) }
^
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Really impossible to use return type overloading?
The problem is that there is an automatic conversion from int to float so it really doesn't know what you intended. Did you...
Read more >Overloads shouldn't differ by the return type of a function type.
There would be error "overloads cannot differ only by return type", which is reasonable. ... The compiler would treat (str: string) => string...
Read more >C++ Core Guidelines - GitHub Pages
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++.
Read more >Effective Dart: Design
When a member produces a result without any side effects, it should usually be a getter or a method with a noun phrase...
Read more >Parser messages - Free Pascal
You're trying to use an overloaded operator when it is not overloaded for this type. Error: Impossible to overload assignment for equal types...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a tentative fix for this, should have something up to review in the next couple of days.
The PR was reverted