Skip to content

Commit

Permalink
Fix bug in combo-chaining.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Nov 27, 2023
1 parent eebe538 commit f3b4918
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Bug fixes
* Fixed crash when parsing multi-segment interpolated string longer than maximum (found via fuzzing).
* Fixed crash when parsing unterminated comment (found via fuzzing).
* Fixed crash when parsing deeply-nested right-associated operators such as `**` (found via fuzzing).
* Fixed crash when parsing combo-chaining expressions such as `(a.b).c` (found via fuzzing).

Deprecated API's
----------------
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ fn optimize_combo_chain(expr: &mut Expr) {
Expr::Dot(mut x, opt, pos) => match x.lhs.take() {
#[cfg(not(feature = "no_index"))]
Expr::Index(x2, opt2, pos2) => (x, opt, pos, x2, opt2, pos2, Expr::Dot, Expr::Index),
Expr::Dot(x2, opt2, pos2) => (x, opt, pos, x2, opt2, pos2, Expr::Dot, Expr::Index),
Expr::Dot(x2, opt2, pos2) => (x, opt, pos, x2, opt2, pos2, Expr::Dot, Expr::Dot),
_ => unreachable!("combo chain expected"),
},
_ => unreachable!("combo chain expected"),
Expand Down
2 changes: 2 additions & 0 deletions tests/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ fn test_map_indexing() {
}

assert_eq!(engine.eval::<INT>("let y = #{a: 1, b: 2, c: 3}; y.a = 5; y.a").unwrap(), 5);
assert_eq!(engine.eval::<INT>("let y = #{a: #{x:9, y:8, z:7}, b: 2, c: 3}; (y.a).z").unwrap(), 7);
assert_eq!(engine.eval::<INT>("let y = #{a: #{x:9, y:8, z:7}, b: 2, c: 3}; (y.a).z = 42; y.a.z").unwrap(), 42);

engine.run("let y = #{a: 1, b: 2, c: 3}; y.z").unwrap();

Expand Down

0 comments on commit f3b4918

Please sign in to comment.