Skip to content

Commit 85cf542

Browse files
authored
Format cast pattern. (#1388)
1 parent efda436 commit 85cf542

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
230230

231231
@override
232232
Piece visitCastPattern(CastPattern node) {
233-
throw UnimplementedError();
233+
return createInfix(node.pattern, node.asToken, node.type);
234234
}
235235

236236
@override

test/pattern/cast.stmt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
40 columns |
2+
>>> Basic cast pattern.
3+
if (object case x as int) {;}
4+
<<<
5+
if (object case x as int) {
6+
;
7+
}
8+
>>> Split before 'case'.
9+
if (object case constant as VeryLongType) {;}
10+
<<<
11+
if (object
12+
case constant as VeryLongType) {
13+
;
14+
}
15+
>>> Split before 'as'.
16+
if (object case veryLongConstant as VeryLongType) {;}
17+
<<<
18+
if (object
19+
case veryLongConstant
20+
as VeryLongType) {
21+
;
22+
}

test/pattern/cast_comment.stmt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
40 columns |
2+
>>> Line comment before pattern.
3+
if (obj case // c
4+
constant as Type) {;}
5+
<<<
6+
if (obj
7+
case // c
8+
constant as Type) {
9+
;
10+
}
11+
>>> Line comment before 'as'.
12+
if (obj case constant // c
13+
as Type) {;}
14+
<<<
15+
if (obj
16+
case constant // c
17+
as Type) {
18+
;
19+
}
20+
>>> Line comment after 'as'.
21+
if (obj case constant as // c
22+
Type) {;}
23+
<<<
24+
if (obj
25+
case constant
26+
as // c
27+
Type) {
28+
;
29+
}

0 commit comments

Comments
 (0)