diff options
author | Nadrieril | 2019-03-11 19:39:13 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-11 19:43:19 +0100 |
commit | 2701c2ca6931b381366e4b58d27ace3943158cf7 (patch) | |
tree | 3827c51f982b868d363cc481a013bc87bb8551ff /dhall_core/src | |
parent | b916bc896851557e63b46af9aa46793472b97da7 (diff) |
Fix stack overflows in prelude tests
Closes #5
Diffstat (limited to '')
-rw-r--r-- | dhall_core/src/core.rs | 57 |
1 files changed, 20 insertions, 37 deletions
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<S, A: Display> Display for Expr<S, A> { } } +// WARNING: this may cause stack overflows when adding new variants impl<S, A: Display> Expr<S, A> { fn fmt_b(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use crate::Expr::*; @@ -495,44 +496,26 @@ impl<S, A: Display> Expr<S, A> { 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), |