Proposal to remove auto application from the language

I agree that consistency between methods and constructors would be desirable. That said, it’s not as necessary because currying constructors and distinguishing between no-arg-list constructors and one-empty-arg-list constructors are not done very often, if at all.

You can use size method instead.

I am in favor of this change because it removes a special case. I would go a little further and hide the Scala-2/Java exemption behind a compiler flag so it can be removed at some point.


I think we should give an error/warning in the following case:

class Foo
object Foo {
  def apply : Foo = new Foo

val foo = Foo //What did we want here? The companion Foo or new instance of class Foo?

Now say we wanted to fix this so it would work properly:

class Foo2
object Foo2 {
  def apply() : Foo2 = new Foo2

val foo = Foo2() //Instance of Foo2

OK, this works, but how do we prevent the user from accidentally using val foo = Foo2 and getting the companion? Just not use a companion at all?

class Foo3
def Foo3 : Foo3 = new Foo3

val foo = Foo3 //Here the user cannot make a mistake

I don’t know if there’s any direct way, but usually the user won’t be able to get too far… unless the object extends its companion class.
More generally, linters should be able to warn if a singleton object that doesn’t extend any interesting types is being assigned to a variable, or if its singleton type is otherwise being used. You almost never need to pass a singleton around, since anyone that wants an instance of the singleton type can just as well use the singleton directly.

That’s why I think that in the above case the compiler can notice the mistake and give the proper error. Otherwise the error will be type mismatch in some fashion which will be very confusing (happened to me and took me several minutes actually to dig up that idiotic thing I did, because it was supposed to be picked up by an implicit conversion).

I am in favor of this proposal to remove auto application.

This topic was automatically closed after 30 days. New replies are no longer allowed.

This topic was automatically closed after 36 days. New replies are no longer allowed.