What does it mean parameterless?

Scala 2 specification:
If a parameterless method defined as def f : T = … or
def f = … overrides a method of type ()T ′ which has an empty parameter list, then f is also assumed to have an

Scala 3 reference:
Stricter conformance rules also apply to overriding of nullary methods. It is no longer allowed to override a parameterless method by a nullary method or vice versa. Instead, both methods must agree exactly in their parameter lists.

class A:
def next(): Int

class B extends A:
def next: Int // overriding error: incompatible type

Parameterless - no parameters list, so def next which might also be an abstract methods, implemented as as val next
Empty parameter list - eg. def next(), there is a list of parameters, but it’s empty. If implemented in subclass in cannot be a val, becouse val cannot have parameters. In the context or Scala 3 reference it seams that nullary method is an alias for method with empty paramter list

2 Likes

It looks like Scala 2 spec uses only “parameterless” (to mean “parameterlistless”), in contrast to “the empty parameter list”, and does not say “nullary”.

The “internal” nomenclature is “nullary” for “parameterlistless” and “nilary” for “has a parameter list that is empty, or Nil”. By extension, “nelary” to mean non-nullary, arity greater than zero.

A recent PR title: Fix spurious "nullary overrides nilary" warning

Those words do not leak into documentation or messages. Here is an example edit showing that this is intentional:

“unary prefix operator definition with empty parameter list” over “empty-paren (nilary) prefix unary operator”

I think it is likely that Dotty inherits usage of “nullary” from “before the fork”. Because it doesn’t contend with the “lax parens” feature in Scala 2, it doesn’t need the innovative vocabulary.

“Programming in Scala” uses “parameterless method”:

Such parameterless methods are quite common in Scala. By contrast, methods defined with empty parentheses, such as def height(): Int, are called empty-paren methods.

So “empty-paren” has that blessing.

Obviously, I prefer “parameterlistless” because “listless” evokes just the right degree of ennui.