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

Merged
merged 5 commits into from
Sep 25, 2024

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

@benharsh benharsh changed the title Improve initializers on classes that inherit Dyno: Improve initializers on classes that inherit Sep 18, 2024
@riftEmber riftEmber self-requested a review September 20, 2024 18:08
frontend/lib/resolution/InitResolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/InitResolver.cpp Show resolved Hide resolved
frontend/lib/resolution/Resolver.cpp Show resolved Hide resolved
frontend/lib/resolution/InitResolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/InitResolver.cpp Show resolved Hide resolved
@benharsh
Copy link
Member Author

I think I've addressed the items above if you want to take another look.

Copy link
Member

@riftEmber riftEmber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

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]>
…omPossibleMentionOfField

Signed-off-by: Ben Harshbarger <[email protected]>
Signed-off-by: Ben Harshbarger <[email protected]>
…sses before an 'init' call

Signed-off-by: Ben Harshbarger <[email protected]>
@benharsh benharsh merged commit 1a61cd3 into chapel-lang:main Sep 25, 2024
7 checks passed
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.

2 participants