question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unhelpful error message when overloading apply without return type

See original GitHub issue

dotty:

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:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bbarkercommented, Jun 30, 2017

I have a tentative fix for this, should have something up to review in the next couple of days.

0reactions
allanrenuccicommented, Jan 18, 2018

The PR was reverted

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found