From 18943f184de8e13c02d69408e14febe0cb09026d Mon Sep 17 00:00:00 2001 From: Erin Date: Sat, 2 Jul 2022 01:17:31 +0200 Subject: [PATCH] cycle detecion on cart print - no longer stack overflow --- ablescript/src/value/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ablescript/src/value/mod.rs b/ablescript/src/value/mod.rs index 3c1dfe7..a9b1576 100644 --- a/ablescript/src/value/mod.rs +++ b/ablescript/src/value/mod.rs @@ -148,13 +148,12 @@ impl Display for Value { cart_vec.sort_by(|x, y| x.0.partial_cmp(y.0).unwrap_or(std::cmp::Ordering::Less)); for (idx, (key, value)) in cart_vec.into_iter().enumerate() { - write!( - f, - "{}{} <= {}", - if idx != 0 { ", " } else { "" }, - value.borrow(), - key - )?; + write!(f, "{}", if idx != 0 { ", " } else { "" },)?; + match &*value.borrow() { + x if std::ptr::eq(x, self) => write!(f, ""), + x => write!(f, "{x}"), + }?; + write!(f, " <= {key}")?; } write!(f, "]")