diff --git a/CHANGELOG.md b/CHANGELOG.md index b7acbd5..54a5a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.10.5 -- 2023-06-26 + +#### Fixed + +- A panic that sometimes occurred in lazy execution mode. + ## v0.10.4 -- 2023-06-02 ### Library diff --git a/Cargo.toml b/Cargo.toml index 6d27be1..ebfe762 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-graph" -version = "0.10.4" +version = "0.10.5" description = "Construct graphs from parsed source code" homepage = "https://github.com/tree-sitter/tree-sitter-graph/" repository = "https://github.com/tree-sitter/tree-sitter-graph/" diff --git a/src/execution/lazy/store.rs b/src/execution/lazy/store.rs index 239cc99..4807153 100644 --- a/src/execution/lazy/store.rs +++ b/src/execution/lazy/store.rs @@ -193,26 +193,34 @@ impl LazyScopedVariables { ) -> Result, ExecutionError> { match values { ScopedValues::Unforced(pairs) => { - let mut map = HashMap::new(); + let mut values = HashMap::new(); let mut debug_infos = HashMap::new(); for (scope, value, debug_info) in pairs.into_iter() { let node = scope .evaluate_as_syntax_node(exec) .with_context(|| format!("Evaluating scope of variable _.{}", name,).into()) .with_context(|| debug_info.0.clone().into())?; - let prev_debug_info = debug_infos.insert(node, debug_info.clone()); - match map.insert(node.index, value.clone()) { - Some(_) => { + match ( + values.insert(node.index, value.clone()), + debug_infos.insert(node.index, debug_info.clone()), + ) { + (Some(_), Some(prev_debug_info)) => { return Err(ExecutionError::DuplicateVariable(format!( "{}.{}", node, name, ))) - .with_context(|| (prev_debug_info.unwrap().0, debug_info.0).into()); + .with_context(|| (prev_debug_info.0, debug_info.0).into()); + } + (Some(_), None) => { + unreachable!( + "previous value for syntax node {} without previous debug info", + node + ) } _ => {} }; } - Ok(map) + Ok(values) } ScopedValues::Forcing => Err(ExecutionError::RecursivelyDefinedScopedVariable( format!("_.{}", name),