Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(cypher): resync on unsupported WITH/RETURN expression (#373)
Martin Vogela2cd1e7c07b9
diff --git a/src/cypher/cypher.c b/src/cypher/cypher.cindex 48b6feb1f..24efd2e45 100644--- a/src/cypher/cypher.c+++ b/src/cypher/cypher.c@@ -1311,6 +1311,29 @@ static int parse_return_item(parser_t *p, cbm_return_item_t *item) {if (rc < 0) {return CBM_NOT_FOUND;}+ /* An unknown function call / indexed expression after a bare identifier+ * (e.g. split(f.path,'/')[0]) is not evaluated, but its balanced+ * parentheses/brackets MUST be consumed so the parser stays in sync. Left+ * unconsumed, the trailing tokens desynced the parser into a misleading+ * default star projection (wrong columns, blank rows) (#373). The column+ * keeps its alias and simply projects empty. */+ if (!item->func && !item->kase) {+ while (check(p, TOK_LPAREN) || check(p, TOK_LBRACKET)) {+ cbm_token_type_t open = peek(p)->type;+ cbm_token_type_t close = (open == TOK_LPAREN) ? TOK_RPAREN : TOK_RBRACKET;+ advance(p);+ int depth = 1;+ while (depth > 0 && !check(p, TOK_EOF)) {+ cbm_token_type_t t = peek(p)->type;+ if (t == open) {+ depth++;+ } else if (t == close) {+ depth--;+ }+ advance(p);+ }+ }+ }/* Optional AS alias */if (match(p, TOK_AS)) {const cbm_token_t *alias = expect(p, TOK_IDENT);diff --git a/tests/test_cypher.c b/tests/test_cypher.cindex 5a027bfd9..c47a9d2b4 100644--- a/tests/test_cypher.c+++ b/tests/test_cypher.c@@ -833,6 +833,31 @@ TEST(cypher_exec_count_distinct_issue239) {PASS();}+/* issue #373: an unsupported computed expression in WITH/RETURN (function call+ * like split(...) or list indexing [..]) must not desync the parser into a+ * misleading default star projection (wrong columns f.name/.../.label, blank+ * rows). The requested column shape is preserved; the unsupported expression+ * projects empty while sibling aggregates still compute. */+TEST(cypher_exec_unsupported_with_expr_resync_issue373) {+ cbm_store_t *s = setup_cypher_store();++ cbm_cypher_result_t r = {0};+ int rc = cbm_cypher_execute(+ s, "MATCH (f:Function) WITH split(f.name)[0] AS top, count(*) AS c RETURN top, c", "test",+ 0, &r);+ ASSERT_EQ(rc, 0);+ ASSERT_NULL(r.error);+ /* Columns are the requested aliases (top, c) — NOT a 3-column star+ * projection of f.name/f.qualified_name/f.label. */+ ASSERT_EQ(r.col_count, 2);+ ASSERT_STR_EQ(r.columns[0], "top");+ ASSERT_STR_EQ(r.columns[1], "c");+ cbm_cypher_result_free(&r);++ cbm_store_close(s);+ PASS();+}+/* issue #242: openCypher label alternation in MATCH — (n:A|B). */TEST(cypher_exec_label_alternation_issue242) {cbm_store_t *s = setup_cypher_store();@@ -2330,6 +2355,7 @@ SUITE(cypher) {RUN_TEST(cypher_exec_where_label_test_issue241);RUN_TEST(cypher_exec_label_alternation_issue242);RUN_TEST(cypher_exec_count_distinct_issue239);+ RUN_TEST(cypher_exec_unsupported_with_expr_resync_issue373);RUN_TEST(cypher_exec_inline_props);RUN_TEST(cypher_parse_where_starts_with);RUN_TEST(cypher_parse_where_contains);