From bd76622543c91df20401ca04d3d226d5144e3a31 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 3 Sep 2024 06:08:34 -0400 Subject: [PATCH] Refactor context method --- dust-lang/src/context.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/dust-lang/src/context.rs b/dust-lang/src/context.rs index 3acbf6d..f2cf5fd 100644 --- a/dust-lang/src/context.rs +++ b/dust-lang/src/context.rs @@ -444,22 +444,16 @@ impl ContextInner { let found = self.update_position_if_found(identifier, position)?; if found { - return Ok(true); - } else if let Some(parent) = &self.parent { - if let Some(parent) = parent.upgrade() { - let found_in_ancestor = parent.update_position_if_found(identifier, position)?; + Ok(true) + } else { + let mut associations = self.associations.write()?; - if !found_in_ancestor { - let mut associations = self.associations.write()?; + log::trace!("Updating {identifier}'s last position to {position:?}"); - log::trace!("Updating {identifier}'s last position to {position:?}"); + associations.insert(identifier.clone(), (ContextData::Reserved, position)); - associations.insert(identifier.clone(), (ContextData::Reserved, position)); - } - } + Ok(false) } - - Ok(false) } fn update_position_if_found( @@ -474,10 +468,14 @@ impl ContextInner { *last_position = position; - Ok(true) - } else { - Ok(false) + return Ok(true); + } else if let Some(parent) = &self.parent { + if let Some(parent) = parent.upgrade() { + return parent.update_position_if_found(identifier, position); + } } + + Ok(false) } }