aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2023-09-20 22:38:40 +0200
committerDanielGavin <danielgavin5@hotmail.com>2023-09-20 22:38:40 +0200
commit61e33aa13f25c9b8f4e8e9087a4c482a484b3bf8 (patch)
tree277534bd8a7c346fc4c637122a1dd9ccc5a33058
parent44eab3849a646fdf4af81c18fafb0a6b448aa709 (diff)
Fix issue with formatting where clause not breaking.
-rw-r--r--src/odin/printer/visit.odin24
-rw-r--r--tools/odinfmt/tests/random/.snapshots/demo.odin12
2 files changed, 19 insertions, 17 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index edc1403..6e9a7f7 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -1499,17 +1499,15 @@ contains_do_in_expression :: proc(p: ^Printer, expr: ^ast.Expr) -> bool {
}
@(private)
-push_where_clauses :: proc(p: ^Printer, clauses: []^ast.Expr) -> ^Document {
+visit_where_clauses :: proc(p: ^Printer, clauses: []^ast.Expr) -> ^Document {
if len(clauses) == 0 {
return empty()
}
- return group(
- nest(
- cons_with_nopl(
- text("where"),
- visit_exprs(p, clauses, {.Add_Comma, .Enforce_Newline}),
- ),
+ return nest(
+ cons_with_nopl(
+ text("where"),
+ visit_exprs(p, clauses, {.Add_Comma, .Enforce_Newline}),
),
)
}
@@ -1699,7 +1697,7 @@ visit_expr :: proc(
document = cons_with_nopl(
document,
- push_where_clauses(p, v.where_clauses),
+ visit_where_clauses(p, v.where_clauses),
)
if len(v.variants) == 0 {
@@ -1784,7 +1782,7 @@ visit_expr :: proc(
document = cons_with_nopl(
document,
- push_where_clauses(p, v.where_clauses),
+ visit_where_clauses(p, v.where_clauses),
)
if v.fields != nil && len(v.fields.list) == 0 {
@@ -1834,10 +1832,14 @@ visit_expr :: proc(
document,
visit_proc_type(p, v.type^, v.body != nil),
)
+
document = cons_with_nopl(
document,
- push_where_clauses(p, v.where_clauses),
+ visit_where_clauses(p, v.where_clauses),
)
+
+ document = group(document)
+
document = cons(document, visit_proc_tags(p, v.tags))
if v.body != nil {
@@ -2513,7 +2515,7 @@ visit_proc_type :: proc(
document = cons_with_nopl(document, text("!"))
}
- return group(document)
+ return document
}
diff --git a/tools/odinfmt/tests/random/.snapshots/demo.odin b/tools/odinfmt/tests/random/.snapshots/demo.odin
index 00a42c5..0ab2124 100644
--- a/tools/odinfmt/tests/random/.snapshots/demo.odin
+++ b/tools/odinfmt/tests/random/.snapshots/demo.odin
@@ -1646,14 +1646,14 @@ where_clauses :: proc() {
}
}
{ // Parametric polymorphism checks
- cross_2d :: proc(a, b: $T/[2]$E) -> E where intrinsics.type_is_numeric(
- E,
- ) {
+ cross_2d :: proc(
+ a, b: $T/[2]$E,
+ ) -> E where intrinsics.type_is_numeric(E) {
return a.x * b.y - a.y * b.x
}
- cross_3d :: proc(a, b: $T/[3]$E) -> T where intrinsics.type_is_numeric(
- E,
- ) {
+ cross_3d :: proc(
+ a, b: $T/[3]$E,
+ ) -> T where intrinsics.type_is_numeric(E) {
x := a.y * b.z - a.z * b.y
y := a.z * b.x - a.x * b.z
z := a.x * b.y - a.y * b.z