Fix bug with bracket postfix when no_index.
This commit is contained in:
parent
cec6748ac6
commit
6d190096fd
@ -622,28 +622,33 @@ impl Expr {
|
|||||||
| Self::Or(_)
|
| Self::Or(_)
|
||||||
| Self::True(_)
|
| Self::True(_)
|
||||||
| Self::False(_)
|
| Self::False(_)
|
||||||
| Self::Unit(_) => false,
|
| Self::Unit(_)
|
||||||
|
| Self::Assignment(_) => false,
|
||||||
|
|
||||||
Self::StringConstant(_)
|
Self::StringConstant(_)
|
||||||
| Self::Stmt(_)
|
| Self::Stmt(_)
|
||||||
| Self::FnCall(_)
|
| Self::FnCall(_)
|
||||||
| Self::Assignment(_)
|
|
||||||
| Self::Dot(_)
|
| Self::Dot(_)
|
||||||
| Self::Index(_)
|
| Self::Index(_)
|
||||||
| Self::Array(_)
|
| Self::Array(_)
|
||||||
| Self::Map(_) => match token {
|
| Self::Map(_) => match token {
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
Token::LeftBracket => true,
|
Token::LeftBracket => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
|
|
||||||
Self::Variable(_) => match token {
|
Self::Variable(_) => match token {
|
||||||
Token::LeftBracket | Token::LeftParen => true,
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
Token::LeftBracket => true,
|
||||||
|
Token::LeftParen => true,
|
||||||
Token::DoubleColon => true,
|
Token::DoubleColon => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
|
|
||||||
Self::Property(_) => match token {
|
Self::Property(_) => match token {
|
||||||
Token::LeftBracket | Token::LeftParen => true,
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
Token::LeftBracket => true,
|
||||||
|
Token::LeftParen => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1267,7 +1272,11 @@ fn parse_primary<'a>(
|
|||||||
parse_index_chain(input, state, expr, token_pos, level + 1, allow_stmt_expr)?
|
parse_index_chain(input, state, expr, token_pos, level + 1, allow_stmt_expr)?
|
||||||
}
|
}
|
||||||
// Unknown postfix operator
|
// Unknown postfix operator
|
||||||
(expr, token) => panic!("unknown postfix operator {:?} for {:?}", token, expr),
|
(expr, token) => panic!(
|
||||||
|
"unknown postfix operator '{}' for {:?}",
|
||||||
|
token.syntax(),
|
||||||
|
expr
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,24 @@ fn test_string() -> Result<(), Box<EvalAltResult>> {
|
|||||||
assert_eq!(engine.eval::<String>(r#""foo" + 123"#)?, "foo123");
|
assert_eq!(engine.eval::<String>(r#""foo" + 123"#)?, "foo123");
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
assert_eq!(engine.eval::<String>("(42).to_string()")?, "42");
|
assert_eq!(engine.eval::<String>("to_string(42)")?, "42");
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
assert_eq!(engine.eval::<char>(r#"let y = "hello"; y[1]"#)?, 'e');
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
assert_eq!(engine.eval::<INT>(r#"let y = "hello"; y.len"#)?, 5);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
assert_eq!(
|
||||||
|
engine.eval::<INT>(r#"let y = "hello"; y.clear(); y.len"#)?,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(engine.eval::<INT>(r#"let y = "hello"; len(y)"#)?, 5);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
assert_eq!(engine.eval::<char>(r#"let y = "hello"; y[y.len-1]"#)?, 'o');
|
assert_eq!(engine.eval::<char>(r#"let y = "hello"; y[y.len-1]"#)?, 'o');
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user