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

Navigation using force-unwrap is parsed as an infix expression with a custom operator #16

Closed
alex-pinkus opened this issue Oct 16, 2021 · 0 comments · Fixed by #36
Closed
Labels
ast-incorrect The grammar causes some code to parse without error, but generate an incorrect result bug Something isn't working error-for-valid-code The grammar causes a parsing error for some code that should parse top-repos-error A failure that shows up in one of the top repos parsed by the `top-repos` script

Comments

@alex-pinkus
Copy link
Owner

From Alamofire at Example/Source/AppDelegate.swift

test case:

        navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem

Output:

(source_file
    (infix_expression
        (navigation_expression (simple_identifier) (navigation_suffix (simple_identifier)))
        (custom_operator)
        (navigation_expression
            (navigation_expression (simple_identifier) (navigation_suffix (simple_identifier)))
            (ERROR (UNEXPECTED 'p')) (navigation_suffix (simple_identifier)))))

Expected output would be something like:

(source_file
    (assignment
        (directly_assignable_expression 
            (navigation_expression
                (navigation_expression
                    (postfix_expression
                        (navigation_expression (simple_identifier) (navigation_suffix (simple_identifier))))
                    (navigation_suffix (simple_identifier)))
                (navigation_suffix (simple_identifier))))
        (navigation_expression (simple_identifier) (navigation_suffix (simple_identifier)))))

Although I would think just treating it as another type of navigation expression would be satisfactory.

@alex-pinkus alex-pinkus added bug Something isn't working error-for-valid-code The grammar causes a parsing error for some code that should parse top-repos-error A failure that shows up in one of the top repos parsed by the `top-repos` script ast-incorrect The grammar causes some code to parse without error, but generate an incorrect result labels Oct 16, 2021
alex-pinkus added a commit that referenced this issue Oct 17, 2021
Fixes #16

Force unwrapping during navigation _should_ just fall naturally out of
the normal postfix operator combined with a basic navigation expression.
Unfortunately, life isn't that simple, and it gets parsed as a custom
infix operator instead. We can nudge things in the right direction by
just declaring a `!.` operator, even though no such operator truly
exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast-incorrect The grammar causes some code to parse without error, but generate an incorrect result bug Something isn't working error-for-valid-code The grammar causes a parsing error for some code that should parse top-repos-error A failure that shows up in one of the top repos parsed by the `top-repos` script
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant