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

Dyno: Improve initializers on classes that inherit #25965

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benharsh
Copy link
Member

This PR improves support for initializers on classes that inherit. With this commit dyno now supports:

  • implicit 'super.init' calls
  • errors for accessing parent fields before 'super.init'
  • usage of initialized fields part-way through initializing the whole type

This PR updates the Resolver to rely somewhat less on 'InitResolver' for explicitly handling Identifier and Dot uAST nodes. Instead we continue to rely on established Resolver mechanisms and selectively invoke the InitResolver when appropriate.

This PR also improves a fix within 'handleCallExpr' originally meant to support receiver-less 'init' calls. Instead, this fix is adapted to any 'init' call within an initializer, and will replace or create the receiver using a fully-generic type. This is done in case the user has erroneously initialized fields prior to the explicit 'init' call. I plan on moving this behavior into InitResolver in the future.


The fieldIdFromPossibleMentionOfField helper method is updated to return a field ID (if found) and whether that field is a parent field.

Some logic from handleCallToSuperInit is split off into a new updateSuperType method to better support the implicit 'super.init' case.

Minor fixes to findFieldByName

  • Use VarLikeDecl instead, as NamedDecl can match primary methods.
  • Do not continue searching upwards if the parent class is the root class.

Lastly, this commit adds tests for newly supported initializer behavior.

  • test-dyno

This commit improves support for initializers on classes that inherit.
With this commit dyno now supports:
- implicit 'super.init' calls
- errors for accessing parent fields before 'super.init'
- usage of initialized fields part-way through initializing the whole type

This commit updates the Resolver to rely somewhat less on 'InitResolver'
for explicitly handling ``Identifier`` and ``Dot`` uAST nodes. Instead
we continue to rely on established Resolver mechanisms and selectively
invoke the ``InitResolver`` when appropriate.

This commit also improves a fix within 'handleCallExpr' originally meant
to support receiver-less 'init' calls. Instead, this fix is adapted to
any 'init' call within an initializer, and will replace or create the
receiver using a fully-generic type. This is done in case the user has
erroneously initialized fields prior to the explicit 'init' call.

------------------

The ``fieldIdFromPossibleMentionOfField`` helper method is updated to
return a field ID (if found) and whether that field is a parent field.

Some logic from ``handleCallToSuperInit`` is split off into a new
``updateSuperType`` method to better support the implicit 'super.init'
case.

Minor fixes to ``findFieldByName``
- Use ``VarLikeDecl`` instead, as ``NamedDecl`` can match primary methods.
- Do not continue searching upwards if the parent class is the root class.

Lastly, this commit adds tests for newly supported initializer behavior

Signed-off-by: Ben Harshbarger <[email protected]>
@benharsh benharsh changed the title Improve initializers on classes that inherit Dyno: Improve initializers on classes that inherit Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant