Skip to content

Commit 0945c9d

Browse files
authored
Don't write trailing commas in split catch clauses. (#1572)
Apparently the language doesn't allow them. Who knew? Fix #1570.
1 parent f46aa31 commit 0945c9d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

lib/src/front_end/piece_factory.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ mixin PieceFactory {
775775
pieces.token(catchKeyword);
776776
pieces.space();
777777

778-
var parameters = DelimitedListBuilder(this);
778+
var parameters = DelimitedListBuilder(
779+
this, const ListStyle(commas: Commas.nonTrailing));
779780
parameters.leftBracket(catchClause.leftParenthesis!);
780781
if (catchClause.exceptionParameter case var exceptionParameter?) {
781782
parameters.visit(exceptionParameter);

test/tall/statement/try.stmt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,33 @@ try {
110110
} on FooException {
111111
} on BarException {
112112
doSomething();
113-
}
113+
}
114+
>>> Split inside catch clause without stack trace.
115+
try {
116+
doSomething();
117+
} catch (someSurprisinglyLongVariableName) {
118+
doSomething();
119+
}
120+
<<<
121+
try {
122+
doSomething();
123+
} catch (
124+
someSurprisinglyLongVariableName
125+
) {
126+
doSomething();
127+
}
128+
>>> Split inside catch clause with stack trace.
129+
try {
130+
doSomething();
131+
} catch (longErrorVariable, longStackTrace) {
132+
doSomething();
133+
}
134+
<<<
135+
try {
136+
doSomething();
137+
} catch (
138+
longErrorVariable,
139+
longStackTrace
140+
) {
141+
doSomething();
142+
}

test/tall/statement/try_comment.stmt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ try {
2727
body;
2828
} catch (
2929
// comment
30-
e,
30+
e
3131
) {
3232
print(e);
3333
}
@@ -38,7 +38,7 @@ try { body; } catch (e// comment
3838
try {
3939
body;
4040
} catch (
41-
e, // comment
41+
e // comment
4242
) {
4343
print(e);
4444
}

0 commit comments

Comments
 (0)