From 12b81d55e1343fc30138d1a13cd48fa2e05744df Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 5 Apr 2020 22:56:45 +0100 Subject: Fix import bug --- dhall/build.rs | 7 +------ dhall/src/semantics/resolve/env.rs | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'dhall') diff --git a/dhall/build.rs b/dhall/build.rs index ec31192..784ce93 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -330,12 +330,7 @@ fn generate_tests() -> std::io::Result<()> { module_name: "type_inference_success", directory: "type-inference/success/", variant: "TypeInferenceSuccess", - exclude_path: Rc::new(|path: &str| { - false - // Too slow, but also not all features implemented - // For now needs support for hashed imports - || path == "prelude" - }), + too_slow_path: Rc::new(|path: &str| path == "prelude"), output_type: Some(FileType::Text), ..default_feature.clone() }, diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index d7ff0ae..6346a6d 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -71,7 +71,7 @@ impl ImportEnv { pub fn handle_import( &mut self, - location: ImportLocation, + mut location: ImportLocation, do_resolve: impl FnOnce(&mut Self) -> Result, ) -> Result { if self.stack.contains(&location) { @@ -82,14 +82,16 @@ impl ImportEnv { Ok(match self.cache.get(&location) { Some(expr) => expr.clone(), None => { - // Push the current location on the stack - self.stack.push(location); - - // Resolve the import recursively - let expr = do_resolve(self)?; - - // Remove location from the stack. - let location = self.stack.pop().unwrap(); + let expr = { + // Push the current location on the stack + self.stack.push(location); + // Resolve the import recursively + // WARNING: do not propagate errors here or the stack will get messed up. + let result = do_resolve(self); + // Remove location from the stack. + location = self.stack.pop().unwrap(); + result + }?; // Add the resolved import to the cache self.cache.insert(location, expr.clone()); -- cgit v1.2.3