Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve static error for incorrect arities of subclass constructors #459

Open
usaoc opened this issue Jan 4, 2024 · 1 comment
Open

Comments

@usaoc
Copy link
Collaborator

usaoc commented Jan 4, 2024

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.

@usaoc
Copy link
Collaborator Author

usaoc commented May 7, 2024

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.

@usaoc usaoc changed the title Requirement for custom constructor should propagate to subclasses Improve static error for incorrect arities of subclass constructors May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant