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

Commits on Sep 25, 2024

  1. Improve initializers on classes that inherit

    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 committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    f47644e View commit details
    Browse the repository at this point in the history
  2. Store aggregate decl in InitResolver, and clean up parts of fieldIdFr…

    …omPossibleMentionOfField
    
    Signed-off-by: Ben Harshbarger <[email protected]>
    benharsh committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    8be4403 View commit details
    Browse the repository at this point in the history
  3. Clean up updateSuperType

    Signed-off-by: Ben Harshbarger <[email protected]>
    benharsh committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    ed366f6 View commit details
    Browse the repository at this point in the history
  4. Allow error message for assigning parent field before super.init and …

    …add test case
    
    Signed-off-by: Ben Harshbarger <[email protected]>
    benharsh committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    ca74bfc View commit details
    Browse the repository at this point in the history
  5. Add note clarifying when errors will be issued for invalid field acce…

    …sses before an 'init' call
    
    Signed-off-by: Ben Harshbarger <[email protected]>
    benharsh committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    a35504e View commit details
    Browse the repository at this point in the history