diff --git a/core/engine/src/environments/runtime/declarative/mod.rs b/core/engine/src/environments/runtime/declarative/mod.rs index 32cfc53469f..f444e36adc1 100644 --- a/core/engine/src/environments/runtime/declarative/mod.rs +++ b/core/engine/src/environments/runtime/declarative/mod.rs @@ -68,6 +68,15 @@ impl DeclarativeEnvironment { &self.kind } + /// Returns whether this environment is a function environment. + pub(crate) fn is_function(&self) -> bool { + if let DeclarativeEnvironmentKind::Function(_) = self.kind() { + true + } else { + false + } + } + /// Gets the binding value from the environment by index. /// /// # Panics diff --git a/core/engine/src/environments/runtime/mod.rs b/core/engine/src/environments/runtime/mod.rs index 8e13398cfc1..1ddc369d2a6 100644 --- a/core/engine/src/environments/runtime/mod.rs +++ b/core/engine/src/environments/runtime/mod.rs @@ -278,7 +278,7 @@ impl EnvironmentStack { .filter_map(Environment::as_declarative) { env.poison(); - if env.compile_env().is_function() { + if env.is_function() { return; } } @@ -513,8 +513,8 @@ impl Context { match self.environment_expect(index) { Environment::Declarative(env) => { if env.poisoned() { - let compile = env.compile_env(); - if compile.is_function() { + if env.is_function() { + let compile = env.compile_env(); if let Some(b) = compile.get_binding(locator.name()) { locator.set_environment(b.environment()); locator.binding_index = b.binding_index(); @@ -578,8 +578,9 @@ impl Context { match self.environment_expect(index) { Environment::Declarative(env) => { if env.poisoned() { - let compile = env.compile_env(); - if compile.is_function() && compile.get_binding(locator.name()).is_some() { + if env.is_function() + && env.compile_env().get_binding(locator.name()).is_some() + { break; } } else if !env.with() {