fork of https://github.com/tree-sitter/tree-sitter-graph

Merge pull request #137 from tree-sitter/unwrap-bug

Attempt at fixing unwrap bug

authored by Hendrik van Antwerpen and committed by GitHub 86aa6723 ef6e334a

Changed files
+21 -7
src
execution
lazy
+6
CHANGELOG.md
··· 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 7 8 + ## v0.10.5 -- 2023-06-26 9 + 10 + #### Fixed 11 + 12 + - A panic that sometimes occurred in lazy execution mode. 13 + 8 14 ## v0.10.4 -- 2023-06-02 9 15 10 16 ### Library
+1 -1
Cargo.toml
··· 1 1 [package] 2 2 name = "tree-sitter-graph" 3 - version = "0.10.4" 3 + version = "0.10.5" 4 4 description = "Construct graphs from parsed source code" 5 5 homepage = "https://github.com/tree-sitter/tree-sitter-graph/" 6 6 repository = "https://github.com/tree-sitter/tree-sitter-graph/"
+14 -6
src/execution/lazy/store.rs
··· 193 193 ) -> Result<HashMap<SyntaxNodeID, LazyValue>, ExecutionError> { 194 194 match values { 195 195 ScopedValues::Unforced(pairs) => { 196 - let mut map = HashMap::new(); 196 + let mut values = HashMap::new(); 197 197 let mut debug_infos = HashMap::new(); 198 198 for (scope, value, debug_info) in pairs.into_iter() { 199 199 let node = scope 200 200 .evaluate_as_syntax_node(exec) 201 201 .with_context(|| format!("Evaluating scope of variable _.{}", name,).into()) 202 202 .with_context(|| debug_info.0.clone().into())?; 203 - let prev_debug_info = debug_infos.insert(node, debug_info.clone()); 204 - match map.insert(node.index, value.clone()) { 205 - Some(_) => { 203 + match ( 204 + values.insert(node.index, value.clone()), 205 + debug_infos.insert(node.index, debug_info.clone()), 206 + ) { 207 + (Some(_), Some(prev_debug_info)) => { 206 208 return Err(ExecutionError::DuplicateVariable(format!( 207 209 "{}.{}", 208 210 node, name, 209 211 ))) 210 - .with_context(|| (prev_debug_info.unwrap().0, debug_info.0).into()); 212 + .with_context(|| (prev_debug_info.0, debug_info.0).into()); 213 + } 214 + (Some(_), None) => { 215 + unreachable!( 216 + "previous value for syntax node {} without previous debug info", 217 + node 218 + ) 211 219 } 212 220 _ => {} 213 221 }; 214 222 } 215 - Ok(map) 223 + Ok(values) 216 224 } 217 225 ScopedValues::Forcing => Err(ExecutionError::RecursivelyDefinedScopedVariable( 218 226 format!("_.{}", name),