From 59d3667a7df108781ce8c5d3385471ce84b1ac96 Mon Sep 17 00:00:00 2001 From: Yann Hamdaoui Date: Thu, 17 Mar 2022 15:02:37 +0100 Subject: [PATCH] Merge null values and empty lists --- src/error.rs | 10 +++++----- src/eval/merge.rs | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 6c728fd8..b359fb7d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -952,13 +952,13 @@ impl ToDiagnostic for EvalError { // (either variable or field) as the name of the missing field. let mut field: Option = None; let mut pos_record = TermPos::None; - let mut pos_access: Option = None; + let mut pos_access = TermPos::None; for elt in callstack.as_ref().iter().rev() { match elt { StackElem::Var { id, pos, .. } if !id.is_generated() && field.is_none() => { field = Some(id.to_string()); - pos_access = Some(*pos); + pos_access = *pos; } StackElem::Field { id, @@ -966,8 +966,8 @@ impl ToDiagnostic for EvalError { pos_access: pos_acc, .. } => { - field.get_or_insert(id.to_string()); - pos_access.get_or_insert(*pos_acc); + field = Some(id.to_string()); + pos_access = *pos_acc; pos_record = *pos_rec; break; } @@ -981,7 +981,7 @@ impl ToDiagnostic for EvalError { labels.push(primary(&span).with_message("in this record")); } - if let Some(span) = pos_access.map(TermPos::into_opt).flatten() { + if let Some(span) = pos_access.into_opt() { labels.push(secondary(&span).with_message("accessed here")); } diff --git a/src/eval/merge.rs b/src/eval/merge.rs index 7bc5262b..3daaf7e5 100644 --- a/src/eval/merge.rs +++ b/src/eval/merge.rs @@ -119,6 +119,10 @@ pub fn merge( match (t1.into_owned(), t2.into_owned()) { // Merge is idempotent on basic terms + (Term::Null, Term::Null) => Ok(Closure::atomic_closure(RichTerm::new( + Term::Null, + pos_op.into_inherited(), + ))), (Term::Bool(b1), Term::Bool(b2)) => { if b1 == b2 { Ok(Closure::atomic_closure(RichTerm::new( @@ -219,6 +223,9 @@ pub fn merge( )) } } + (Term::Array(arr1), Term::Array(arr2)) if arr1.is_empty() && arr2.is_empty() => Ok( + Closure::atomic_closure(RichTerm::new(Term::Array(arr1), pos_op.into_inherited())), + ), (Term::MetaValue(meta1), Term::MetaValue(meta2)) => { // For now, we blindly closurize things and copy environments in this section. A // careful analysis would make it possible to spare a few closurize operations and more