Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[bug] Overlapping Parent and Child AST Nodes Ambiguity #1427

Copy link
Copy link
@StevenLove

Description

@StevenLove
Issue body actions

This may not be a bug, but I'm looking for clarification. There are ambiguous situations where a parent and child node overlap entirely and each contain the same sequence of characters. When we use a pattern in a situation like this, both the parent and child nodes are reasonable matches. Is there a rationale behind whether ast-grep matches the parent or the child?

Further, it feels like using all to order the rules and starting with kind and refining with pattern should be able to match the expression_statement even if the pattern wants to match the binary_expression over the expression_statement

  all:
    - kind: expression_statement # doesn't match
    - pattern: $A == $B
image

⏯ Playground Link

Playground link with relevant code

💻 Code

Code:

a == b

Pattern:

rule:
  pattern: $A == $B
  kind: expression_statement # doesn't match

🙁 Actual behavior

While the expression_statement node does fit the pattern, it won't be matched. Instead the child binary_expression is matched

🙂 Expected behavior

A matching expression_statement is found

Discussion

This leads to confusing situations where follows doesn't work as expected because the matched nodes are children and require us to use inside, then follows, and then has as discussed here

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.