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

Introduce leaf protocols to prevent leaf nodes from being casted #2108

Merged
merged 3 commits into from
Sep 6, 2023

Commits on Sep 6, 2023

  1. Introduce leaf protocols to prevent leaf nodes from being casted

    This commit addresses an issue in the implementation of `SyntaxProtocol` where the 'as' method allows casting to any other syntax node type. This leads to problematic scenarios, such as casting a 'FunctionDeclSyntax' to an 'IdentifierExprSyntax' without compiler warnings, despite the cast being destined to fail at runtime.
    To solve this, specialized leaf protocols have been introduced. These restrict casting options to only those that are meaningful within the same base node type, thereby enhancing type safety and reducing the risk of runtime errors.
    Matejkob committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    c2bdd2e View commit details
    Browse the repository at this point in the history
  2. Add deprecated warnings for same-type casts in SyntaxProtocol

    - Implement overloads for `is`, `as`, and `cast` methods in SyntaxProtocol to handle same-type conversions.
    - Mark these overloaded methods as deprecated with a warning message that the cast will always succeed.
    - Update the codebase to eliminate a redundant casts.
    Matejkob committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    0c0bf90 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d2945f8 View commit details
    Browse the repository at this point in the history