Improve static error for incorrect arities of subclass constructors
Classes with private immutable fields are currently required to have custom constructors. For example,
#lang rhombus
class Secret(private _secret)
this triggers “class needs a custom constructor to initialize private immutable fields”, while
#lang rhombus
class Secret(private _secret):
constructor (secr):
super(secr)
this works. However, this requirement doesn’t seem to properly propagate. For example,
#lang rhombus
class Secret(private _secret):
nonfinal
constructor (secr):
super(secr)
class TopSecret():
extends Secret
this does not trigger “class needs a custom constructor to initialize private immutable fields”, but it simply cannot work.
This seems to be a more general problem, because the following program
#lang rhombus
class Secret(secret):
nonfinal
constructor ():
super("not secret")
class TopSecret():
extends Secret
doesn’t trigger any static error, either. Actually, this is a documented behavior (keeping in mind that private fields are not visible to subclasses):
If a superclass has a custom constructor, the default constructor of a subclass assumes that the superclass constructor accepts the same argument as the default superclass constructor.
However, I think a best-effort static error can still help a lot in such cases.