diff --git a/src/query/frontend/semantic/symbol_generator.cpp b/src/query/frontend/semantic/symbol_generator.cpp index 2dba945c4..4a788dc47 100644 --- a/src/query/frontend/semantic/symbol_generator.cpp +++ b/src/query/frontend/semantic/symbol_generator.cpp @@ -270,7 +270,8 @@ bool SymbolGenerator::PreVisit(NodeAtom &node_atom) { bool props_or_labels = !node_atom.properties_.empty() || !node_atom.labels_.empty(); const auto &node_name = node_atom.identifier_->name_; - if (scope_.in_create && props_or_labels && HasSymbol(node_name)) { + if ((scope_.in_create || scope_.in_merge) && props_or_labels && + HasSymbol(node_name)) { throw SemanticException( "Cannot create node '" + node_name + "' with labels or properties, because it is already declared."); diff --git a/tests/unit/query_semantic.cpp b/tests/unit/query_semantic.cpp index b1fd700ad..617e91823 100644 --- a/tests/unit/query_semantic.cpp +++ b/tests/unit/query_semantic.cpp @@ -840,4 +840,20 @@ TEST(TestSymbolGenerator, MatchReturnAsteriskNoUserVariables) { EXPECT_THROW(query->Accept(symbol_generator), SemanticException); } +TEST(TestSymbolGenerator, MatchMergeExpandLabel) { + // Test MATCH (n) MERGE (m) -[r :r]-> (n:label) + Dbms dbms; + auto dba = dbms.active(); + auto r_type = dba->edge_type("r"); + auto label = dba->label("label"); + AstTreeStorage storage; + auto query = QUERY( + MATCH(PATTERN(NODE("n"))), + MERGE(PATTERN(NODE("m"), EDGE("r", r_type, EdgeAtom::Direction::RIGHT), + NODE("n", label)))); + SymbolTable symbol_table; + SymbolGenerator symbol_generator(symbol_table); + EXPECT_THROW(query->Accept(symbol_generator), SemanticException); +} + } // namespace