From 7ce88873432a1ac4e39afaed082e9eaa70153126 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 28 Sep 2021 16:36:31 +0800 Subject: [PATCH] Fix no_index build. --- src/engine.rs | 1 + tests/get_set.rs | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index d0847bac..cd28772f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -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"))] diff --git a/tests/get_set.rs b/tests/get_set.rs index 5febe240..83dacc0b 100644 --- a/tests/get_set.rs +++ b/tests/get_set.rs @@ -224,25 +224,32 @@ fn test_get_set_chain_without_write_back() -> Result<(), Box> { "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::(&mut scope, "outer.inner.value")?, 42 ); + + #[cfg(not(feature = "no_index"))] assert_eq!( engine.eval_with_scope::(&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(())