From 2701c2ca6931b381366e4b58d27ace3943158cf7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Mar 2019 19:39:13 +0100 Subject: Fix stack overflows in prelude tests Closes #5 --- dhall_core/src/core.rs | 57 ++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 481e949..9c96b2a 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -405,6 +405,7 @@ impl Display for Expr { } } +// WARNING: this may cause stack overflows when adding new variants impl Expr { fn fmt_b(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use crate::Expr::*; @@ -495,44 +496,26 @@ impl Expr { use crate::Expr::*; match self { // FIXME precedence - &BinOp(BoolOr, ref a, ref b) => { + &BinOp(op, ref a, ref b) => { a.fmt_d(f)?; - f.write_str(" || ")?; - b.fmt_c(f) - } - &BinOp(TextAppend, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" ++ ")?; - b.fmt_c(f) - } - &BinOp(NaturalPlus, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" + ")?; - b.fmt_c(f) - } - &BinOp(BoolAnd, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" && ")?; - b.fmt_c(f) - } - &BinOp(Combine, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" ^ ")?; - b.fmt_c(f) - } - &BinOp(NaturalTimes, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" * ")?; - b.fmt_c(f) - } - &BinOp(BoolEQ, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" == ")?; - b.fmt_c(f) - } - &BinOp(BoolNE, ref a, ref b) => { - a.fmt_d(f)?; - f.write_str(" != ")?; + write!( + f, + " {} ", + match op { + BoolOr => "||", + TextAppend => "++", + NaturalPlus => "+", + BoolAnd => "&&", + Combine => "^", + NaturalTimes => "*", + BoolEQ => "==", + BoolNE => "!=", + CombineTypes => "//\\", + ImportAlt => "?", + Prefer => "//", + ListAppend => "#", + } + )?; b.fmt_c(f) } &Note(_, ref b) => b.fmt_c(f), -- cgit v1.2.3