You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not possible to use the ? operator in binding rule queries. The reason is the query engine will not create a capture key when the node is absent and this causes a panic when the graph builder attempts to evaluate the capture value.
thread 'bindings_output::generated::mappings::named_parameters' panicked at /home/ggiraldez/Projects/slang/crates/metaslang/graph_builder/src/execution/lazy.rs:691:41:
no entry found for key
CAVEAT: Whether we want to fix this or not is up for debate. Because our query engine works more like unification than pattern matching, the above rule would be problematic as it will match twice if the Identifier is present: one time capturing it, and a second time without capturing it. This problem gets worse if the query contains multiple optional captures, as the engine will return matches for all possible combinations.
The text was updated successfully, but these errors were encountered:
This patch would fix the issue, but as stated in the caveat above, this could potentially result in a more confusing behaviour. It's also unclear to me that the resulting behaviour is useful for implementing the binding rules.
diff --git a/crates/metaslang/graph_builder/src/execution/lazy.rs b/crates/metaslang/graph_builder/src/execution/lazy.rs
index 9b589607b..8a74631ac 100644
--- a/crates/metaslang/graph_builder/src/execution/lazy.rs+++ b/crates/metaslang/graph_builder/src/execution/lazy.rs@@ -688,8 +688,12 @@ impl ast::Capture {
&self,
exec: &mut ExecutionContext<'_, '_, '_, KT>,
) -> Result<LazyValue, ExecutionError> {
- let capture = &exec.mat.captures[&*self.name.0];- Ok(Value::from_nodes(exec.graph, capture.iter().cloned(), self.quantifier).into())+ let value = if let Some(capture) = &exec.mat.captures.get(&*self.name.0) {+ Value::from_nodes(exec.graph, capture.iter().cloned(), self.quantifier)+ } else {+ Value::from_nodes(exec.graph, std::iter::empty().into_iter(), self.quantifier)+ };+ Ok(value.into())
}
}
It's not possible to use the
?
operator in binding rule queries. The reason is the query engine will not create a capture key when the node is absent and this causes a panic when the graph builder attempts to evaluate the capture value.Eg. the rule for Solidity:
Will panic here with:
CAVEAT: Whether we want to fix this or not is up for debate. Because our query engine works more like unification than pattern matching, the above rule would be problematic as it will match twice if the
Identifier
is present: one time capturing it, and a second time without capturing it. This problem gets worse if the query contains multiple optional captures, as the engine will return matches for all possible combinations.The text was updated successfully, but these errors were encountered: