Fix unbound variable causing crash inside subquery (#1710)

This commit is contained in:
Ivan Milinović
2024-02-13 01:10:03 +01:00
committed by GitHub
parent 4f4a569c72
commit 7688a1b068
2 changed files with 23 additions and 2 deletions

View File

@@ -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);