From 678507bcbe7b5d6916941003f4b60dd924c9cdba Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 15 Oct 2023 17:43:09 +0100 Subject: [PATCH] Add support for comparing equality on reflective values --- hornbeam_interpreter/src/engine.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hornbeam_interpreter/src/engine.rs b/hornbeam_interpreter/src/engine.rs index cb4826a..f7f1934 100644 --- a/hornbeam_interpreter/src/engine.rs +++ b/hornbeam_interpreter/src/engine.rs @@ -576,6 +576,16 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret match (lval, rval) { (Value::Bool(lbool), Value::Bool(rbool)) => Ok(Value::Bool(lbool == rbool)), (Value::Int(lint), Value::Int(rint)) => Ok(Value::Bool(lint == rint)), + (Value::Reflective(lreflect), Value::Reflective(rreflect)) => { + match lreflect.reflect_partial_eq(rreflect.as_ref()) { + Some(answer) => Ok(Value::Bool(answer)), + None => Err(InterpreterError::TypeError { + context: "Equals".to_string(), + conflict: format!("can't test reflectives {lreflect:?} and {rreflect:?} for equality: they don't support it!"), + location: loc.clone(), + }) + } + }, (lother, rother) => Err(InterpreterError::TypeError { context: "Equals".to_string(), conflict: format!("can't test {lother:?} and {rother:?} for equality!"),