fix(rust): EqCapture accepted cases where number of captured nodes differed by one
Problem: When using alternations, the `#eq?` predicate does not always use the same capture name.
Solution: Iterate the left and right captured nodes more independently.
(cherry picked from commit 79177a1cd5)
This commit is contained in:
parent
25d63ab7ab
commit
17cb10a677
2 changed files with 60 additions and 3 deletions
|
|
@ -2988,6 +2988,61 @@ fn test_query_matches_with_deeply_nested_patterns_with_fields() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_alternations_and_predicates() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("java");
|
||||
let query = Query::new(
|
||||
&language,
|
||||
"
|
||||
(block
|
||||
[
|
||||
(local_variable_declaration
|
||||
(variable_declarator
|
||||
(identifier) @def.a
|
||||
(string_literal) @lit.a
|
||||
)
|
||||
)
|
||||
(local_variable_declaration
|
||||
(variable_declarator
|
||||
(identifier) @def.b
|
||||
(null_literal) @lit.b
|
||||
)
|
||||
)
|
||||
]
|
||||
(expression_statement
|
||||
(method_invocation [
|
||||
(argument_list
|
||||
(identifier) @ref.a
|
||||
(string_literal)
|
||||
)
|
||||
(argument_list
|
||||
(null_literal)
|
||||
(identifier) @ref.b
|
||||
)
|
||||
])
|
||||
)
|
||||
(#eq? @def.a @ref.a )
|
||||
(#eq? @def.b @ref.b )
|
||||
)
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_query_matches(
|
||||
&language,
|
||||
&query,
|
||||
r#"
|
||||
void test() {
|
||||
int a = "foo";
|
||||
f(null, b);
|
||||
}
|
||||
"#,
|
||||
&[],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_indefinite_step_containing_no_captures() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue