Auto-application is deprecated

I don’t understand this warning message from the compiler.

Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method size,
or remove the empty argument list from its definition (Java-defined methods are exempt).
In Scala 3, an unapplied method like this will be eta-expanded into a function.
      assert(BddFalse.size() == 1)

Is the wording of the message awkward or am I just not thinking about it correctly?
I have a method defined as

def size():Int = { ... }

and my call-site uses parens to call the method.
If I remove the parens from the definition and call site, I suppose it will work.
However, the warning message implies that I will still be able to reference the method itself as an eta expansion by omitting the parens.

How can omitting the parens be both a call to the method and also an eta expanded function? Don’t we need two different syntax(es) for two very different semantics?

By the way, I hoped to define the method and call the method with empty parens to emphasize to the caller that this computation might be compute intensive, as it is in some cases a tree traversal which is exponential size w.r.t. the tree depth.

Do I need to add a dummy, unused argument, if I want to retain the parens?

I have tested it, and if I redefine the method like this, everyone seems happy.

def size(unused:Int=0):Int = { ... }

The warning seems wrong, not sure if it is an error in the IDE, or in the compiler. Or maybe, you are not showing all the code, can you create an Scastie that reproduce the problem?

What the warning is trying to tell you is that if size was defined like: def size(): Int = { ??? } then at usage site you must call it like foo.size() instead of just foo.size, the reason being that () becomes a standard in the community to indicate the function is expensive or have side-effects.


I agree something else is going on. Sometimes assert in testing is a macro, maybe the macro erroneously emitted code without parens.

There are also interactions if size overrides a method in a Java class.

Which version of Scala? They flip-flopped on how to transition to Scala 3 conventions.

No workaround such as the proposed dummy parameter should be necessary.

1 Like