Skip to content

unhelpful error message when overloading apply without return type #1731

Closed
@smarter

Description

@smarter

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]) }
                                                                 ^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions