Allow variables in scope for strict vars.
This commit is contained in:
parent
6f4cc91451
commit
a6c2c00479
@ -12,7 +12,7 @@ Bug fixes
|
|||||||
Script-breaking changes
|
Script-breaking changes
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
* _Strict Variables Mode_ no longer returns an error when an undeclared variable matches a constant in the provided external `Scope`.
|
* _Strict Variables Mode_ no longer returns an error when an undeclared variable matches a variable/constant in the provided external `Scope`.
|
||||||
|
|
||||||
Enhancements
|
Enhancements
|
||||||
------------
|
------------
|
||||||
|
@ -1301,10 +1301,7 @@ impl Engine {
|
|||||||
if settings.options.strict_var
|
if settings.options.strict_var
|
||||||
&& !settings.is_closure_scope
|
&& !settings.is_closure_scope
|
||||||
&& index.is_none()
|
&& index.is_none()
|
||||||
&& !matches!(
|
&& !state.scope.contains(name)
|
||||||
state.scope.get_index(name),
|
|
||||||
Some((_, AccessMode::ReadOnly))
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// If the parent scope is not inside another capturing closure
|
// If the parent scope is not inside another capturing closure
|
||||||
// then we can conclude that the captured variable doesn't exist.
|
// then we can conclude that the captured variable doesn't exist.
|
||||||
@ -1450,7 +1447,7 @@ impl Engine {
|
|||||||
|
|
||||||
if settings.options.strict_var
|
if settings.options.strict_var
|
||||||
&& index.is_none()
|
&& index.is_none()
|
||||||
&& !matches!(state.scope.get_index(&s), Some((_, AccessMode::ReadOnly)))
|
&& !state.scope.contains(&s)
|
||||||
{
|
{
|
||||||
return Err(
|
return Err(
|
||||||
PERR::VariableUndefined(s.to_string()).into_err(settings.pos)
|
PERR::VariableUndefined(s.to_string()).into_err(settings.pos)
|
||||||
|
@ -57,7 +57,7 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
|
|||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
scope.push_constant("x", 42 as INT);
|
scope.push("x", 42 as INT);
|
||||||
scope.push_constant("y", 0 as INT);
|
scope.push_constant("y", 0 as INT);
|
||||||
|
|
||||||
engine.compile("let x = if y { z } else { w };")?;
|
engine.compile("let x = if y { z } else { w };")?;
|
||||||
@ -114,8 +114,8 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval_with_scope::<INT>(&mut scope, "fn foo(z) { x * y + z } foo(1)")?,
|
engine.eval_with_scope::<INT>(&mut scope, "fn foo(z) { y + z } foo(x)")?,
|
||||||
1
|
42
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user