From 891de051e2a33afd1f0b677e72965618348980f3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 25 Jun 2020 15:05:44 -0700 Subject: [PATCH] Fix population of subgraph nodes when analyzing queries --- cli/src/tests/query_test.rs | 8 ++++++++ lib/src/query.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index cc42a70d..4c2f65ab 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -2083,6 +2083,14 @@ fn test_query_is_definite() { } let rows = &[ + Row { + language: get_language("python"), + pattern: r#"(expression_statement (string))"#, + results_by_step_index: &[ + (0, false), + (1, false), // string + ], + }, Row { language: get_language("javascript"), pattern: r#"(object "{" "}")"#, diff --git a/lib/src/query.c b/lib/src/query.c index bc277bf9..fa0edba1 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -748,10 +748,9 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *impossible_index for (unsigned i = 0; i < count; i++) { const TSParseAction *action = &actions[i]; if (action->type == TSParseActionTypeReduce) { - unsigned exists; array_search_sorted_by( &subgraphs, - subgraph_index, + 0, .symbol, action->params.reduce.symbol, &subgraph_index, @@ -759,13 +758,14 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *impossible_index ); if (exists) { SymbolSubgraph *subgraph = &subgraphs.contents[subgraph_index]; + SubgraphNode node = { + .state = state, + .production_id = action->params.reduce.production_id, + .child_index = action->params.reduce.child_count, + .done = true, + }; if (subgraph->nodes.size == 0 || array_back(&subgraph->nodes)->state != state) { - array_push(&subgraph->nodes, ((SubgraphNode) { - .state = state, - .production_id = action->params.reduce.production_id, - .child_index = action->params.reduce.child_count, - .done = true, - })); + array_push(&subgraph->nodes, node); } } } else if (