Fix bug in chained dot/index expression.

This commit is contained in:
Stephen Chung 2020-05-31 14:27:16 +08:00
parent 76d792011f
commit d7d49a5196
2 changed files with 6 additions and 2 deletions

View File

@ -1064,7 +1064,7 @@ impl Engine {
// xxx.prop[expr] | xxx.prop.expr // xxx.prop[expr] | xxx.prop.expr
Expr::Index(x) | Expr::Dot(x) => { Expr::Index(x) | Expr::Dot(x) => {
let (prop, expr, pos) = x.as_ref(); let (prop, expr, pos) = x.as_ref();
let is_idx = matches!(expr, Expr::Index(_)); let is_idx = matches!(rhs, Expr::Index(_));
let args = &mut [obj, &mut Default::default()]; let args = &mut [obj, &mut Default::default()];
let (mut val, updated) = if let Expr::Property(p) = prop { let (mut val, updated) = if let Expr::Property(p) = prop {
@ -1102,7 +1102,7 @@ impl Engine {
} }
// Syntax error // Syntax error
_ => Err(Box::new(EvalAltResult::ErrorDotExpr( _ => Err(Box::new(EvalAltResult::ErrorDotExpr(
"".into(), format!("{:?}", rhs),
rhs.position(), rhs.position(),
))), ))),
} }

View File

@ -21,6 +21,10 @@ fn test_map_indexing() -> Result<(), Box<EvalAltResult>> {
)?, )?,
'o' 'o'
); );
assert_eq!(
engine.eval::<String>(r#"let a = [#{s:"hello"}]; a[0].s[2] = 'X'; a[0].s"#)?,
"heXlo"
);
} }
assert_eq!( assert_eq!(