hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7e66b9a02b3a4e7c42dfde567094a1055dda3076
parent 7af19b289ed4422e2a66903d827bf0becf4b5c9b
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sun, 10 Apr 2022 21:19:46 -0400

unparse: return correct size for tagged and tuple

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/unparse/type.ha | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha @@ -236,7 +236,7 @@ export fn _type( n += struct_union_type(out, indent, t)?; case let t: ast::tagged_type => // rough estimate of current line length - let linelen: size = n + (indent + 1) * 8; + let linelen = n; n = 0; linelen += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { @@ -245,9 +245,9 @@ export fn _type( linelen += fmt::fprint(out, " |")?; // use 72 instead of 80 to give a bit of leeway for long // type names - if (linelen > 72) { + if (linelen + (indent + 1) * 8 > 72) { n += linelen; - linelen = (indent + 1) * 8; + linelen = 0; n += fmt::fprintln(out)?; for (let i = 0z; i <= indent; i += 1) { n += fmt::fprint(out, "\t")?; @@ -260,7 +260,7 @@ export fn _type( n += fmt::fprint(out, ")")?; case let t: ast::tuple_type => // rough estimate of current line length - let linelen: size = n + (indent + 1) * 8; + let linelen = n; n = 0; linelen += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { @@ -269,9 +269,9 @@ export fn _type( linelen += fmt::fprint(out, ",")?; // use 72 instead of 80 to give a bit of leeway for long // type names - if (linelen > 72) { + if (linelen + (indent + 1) * 8 > 72) { n += linelen; - linelen = (indent + 1) * 8; + linelen = 0; n += fmt::fprintln(out)?; for (let i = 0z; i <= indent; i += 1) { n += fmt::fprint(out, "\t")?;