Fix no_index build.

This commit is contained in:
Stephen Chung 2021-09-28 16:36:31 +08:00
parent b90776911d
commit 7ce8887343
2 changed files with 16 additions and 8 deletions

View File

@ -338,6 +338,7 @@ impl ChainArgument {
/// Return the [position][Position].
#[inline(always)]
#[must_use]
#[allow(dead_code)]
pub const fn position(&self) -> Position {
match self {
#[cfg(not(feature = "no_object"))]

View File

@ -224,25 +224,32 @@ fn test_get_set_chain_without_write_back() -> Result<(), Box<EvalAltResult>> {
"inner",
|t: &mut Outer| t.inner.clone(),
|_: &mut Outer, new: Inner| panic!("Outer::inner setter called with {:?}", new),
)
.register_indexer_get_set(
|t: &mut Outer, n: INT| Inner {
value: t.inner.value * n,
},
|_: &mut Outer, n: INT, new: Inner| {
panic!("Outer::inner index setter called with {} and {:?}", n, new)
},
);
#[cfg(not(feature = "no_index"))]
engine.register_indexer_get_set(
|t: &mut Outer, n: INT| Inner {
value: t.inner.value * n,
},
|_: &mut Outer, n: INT, new: Inner| {
panic!("Outer::inner index setter called with {} and {:?}", n, new)
},
);
assert_eq!(
engine.eval_with_scope::<INT>(&mut scope, "outer.inner.value")?,
42
);
#[cfg(not(feature = "no_index"))]
assert_eq!(
engine.eval_with_scope::<INT>(&mut scope, "outer[2].value")?,
84
);
engine.consume_with_scope(&mut scope, "print(outer.inner.value)")?;
#[cfg(not(feature = "no_index"))]
engine.consume_with_scope(&mut scope, "print(outer[0].value)")?;
Ok(())