Fix unbound variable causing crash inside subquery (#1710)
This commit is contained in:
parent
4f4a569c72
commit
7688a1b068
@ -1,4 +1,4 @@
|
||||
// Copyright 2023 Memgraph Ltd.
|
||||
// Copyright 2024 Memgraph Ltd.
|
||||
//
|
||||
// Use of this software is governed by the Business Source License
|
||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||
@ -394,9 +394,16 @@ SymbolGenerator::ReturnType SymbolGenerator::Visit(Identifier &ident) {
|
||||
// can reference symbols bound later in the same MATCH. We collect them
|
||||
// here, so that they can be checked after visiting Match.
|
||||
scope.identifiers_in_match.emplace_back(&ident);
|
||||
} else if (scope.in_call_subquery && !scope.in_with) {
|
||||
if (!scope.symbols.contains(ident.name_) && !ConsumePredefinedIdentifier(ident.name_)) {
|
||||
throw UnboundVariableError(ident.name_);
|
||||
}
|
||||
symbol = GetOrCreateSymbol(ident.name_, ident.user_declared_, Symbol::Type::ANY);
|
||||
} else {
|
||||
// Everything else references a bound symbol.
|
||||
if (!HasSymbol(ident.name_) && !ConsumePredefinedIdentifier(ident.name_)) throw UnboundVariableError(ident.name_);
|
||||
if (!HasSymbol(ident.name_) && !ConsumePredefinedIdentifier(ident.name_)) {
|
||||
throw UnboundVariableError(ident.name_);
|
||||
}
|
||||
symbol = GetOrCreateSymbol(ident.name_, ident.user_declared_, Symbol::Type::ANY);
|
||||
}
|
||||
ident.MapTo(symbol);
|
||||
|
@ -185,6 +185,20 @@ Feature: Subqueries
|
||||
"""
|
||||
Then an error should be raised
|
||||
|
||||
Scenario: Subquery with an unbound variable
|
||||
Given an empty graph
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (node1)
|
||||
CALL {
|
||||
MATCH (node2)
|
||||
WHERE node1.property > 0
|
||||
return 1 as state
|
||||
}
|
||||
return 1
|
||||
"""
|
||||
Then an error should be raised
|
||||
|
||||
Scenario: Subquery returning primitive but not aliased
|
||||
Given an empty graph
|
||||
And having executed
|
||||
|
Loading…
Reference in New Issue
Block a user