Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for type arguments in object patterns and remove a TODO. #1401

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/src/back_end/code_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ class CodeWriter {
var parentIndent = _indentStack.last.indent;
var parentCollapse = _indentStack.last.collapsible;

if (canCollapse) {
// Increase the indent and the collapsible indent.
_indentStack.add(_Indent(parentIndent + indent, parentCollapse + indent));
} else if (parentCollapse > indent) {
// All new indent is collapsed with the existing collapsible indent.
_indentStack.add(_Indent(parentIndent, parentCollapse - indent));
if (parentCollapse == indent) {
// We're indenting by the same existing collapsible amount, so collapse
// this new indentation with that existing one.
_indentStack.add(_Indent(parentIndent, 0));
} else if (canCollapse) {
// We should never get multiple levels of nested collapsible indentation.
assert(parentCollapse == 0);

// Increase the indentation and note that it can be collapsed with
// further indentation.
_indentStack.add(_Indent(parentIndent + indent, indent));
} else {
// Use up the collapsible indent (if any) and then indent by the rest.
indent -= parentCollapse;
// Regular indentation, so just increase the indent.
_indentStack.add(_Indent(parentIndent + indent, 0));
}
}
Expand Down
32 changes: 27 additions & 5 deletions test/pattern/object.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,25 @@ if (obj case Foo(
)) {
;
}
>>> Split in type argument.
>>> Split in type argument with no field subpatterns.
if (obj case LongClassName<First, Second>()) {;}
<<<
### TODO(tall): It formats like this if there's no elements. Similarly with lists, maps etc.
if (obj
case LongClassName<
First,
Second
First,
Second
>()) {
;
}
>>> Split in type argument and body.
>>> Prefer splitting in field subpatterns instead of type arguments.
if (obj case Foo<First, Second>(first: 1)) {;}
<<<
if (obj case Foo<First, Second>(
first: 1,
)) {
;
}
>>> Split in type argument but not field subpatterns.
if (obj case LongClassName<First, Second, Third>(first: 1, second: 2, third: 3)) {;}
<<<
if (obj case LongClassName<
Expand All @@ -186,3 +193,18 @@ if (obj case LongClassName<
>(first: 1, second: 2, third: 3)) {
;
}
>>> Split in type arguments and field subpatterns.
if (obj case LongClassName<First, Second, Third>(first: 1, second: 2, third: 3, fourth: 4)) {;}
<<<
if (obj case LongClassName<
First,
Second,
Third
>(
first: 1,
second: 2,
third: 3,
fourth: 4,
)) {
;
}