Skip to content

Commit dd11dd4

Browse files
fix(grainfmt): Group expressions inside array accessors (#1462)
1 parent d321f84 commit dd11dd4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

compiler/src/formatting/format.re

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,15 +2454,19 @@ and print_expression =
24542454
Doc.concat([
24552455
print_expression(~original_source, ~comments, expression1),
24562456
Doc.lbracket,
2457-
print_expression(~original_source, ~comments, expression2),
2457+
Doc.group(
2458+
print_expression(~original_source, ~comments, expression2),
2459+
),
24582460
Doc.rbracket,
24592461
])
24602462
| PExpArraySet(expression1, expression2, expression3) =>
24612463
Doc.group(
24622464
Doc.concat([
24632465
print_expression(~original_source, ~comments, expression1),
24642466
Doc.lbracket,
2465-
print_expression(~original_source, ~comments, expression2),
2467+
Doc.group(
2468+
print_expression(~original_source, ~comments, expression2),
2469+
),
24662470
Doc.rbracket,
24672471
Doc.space,
24682472
Doc.text("="),

compiler/test/formatter_inputs/arrays.gr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ let addRepeatedGroup = (groupN, state, pos, n, backAmt, callback) => {
3737
}
3838
}
3939
}
40+
41+
export let getBefore = (array, index) => if (array == [>]) "nope" else array[index - 1]

compiler/test/formatter_outputs/arrays.gr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ let addRepeatedGroup = (groupN, state, pos, n, backAmt, callback) => {
3636
},
3737
}
3838
}
39+
40+
export let getBefore = (array, index) => if (array == [>]) "nope"
41+
else array[index - 1]

0 commit comments

Comments
 (0)