Skip to content

Commit

Permalink
Merge pull request #137 from tree-sitter/unwrap-bug
Browse files Browse the repository at this point in the history
Attempt at fixing unwrap bug
  • Loading branch information
hendrikvanantwerpen authored Jun 26, 2023
2 parents ef6e334 + 9486df0 commit 86aa672
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
20 changes: 14 additions & 6 deletions src/execution/lazy/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,34 @@ impl LazyScopedVariables {
) -> Result<HashMap<SyntaxNodeID, LazyValue>, 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),
Expand Down

0 comments on commit 86aa672

Please # to comment.