Skip to content

Commit 8c0e44e

Browse files
authored
Preserve type parameters in function-typed "this." and "super." params. (#1520)
Preserve type parameters in function-typed "this." and "super." params. If you have a parameter that: - uses "this." or "super.", - and also uses the old function-typed formal parameter syntax, - and also is a generic function... then the short style formatter would drop the type parameters on the floor. The tall style already does the right thing. Fix the short style and add regression tests for both. Fix #1321.
1 parent 1cf42fa commit 8c0e44e

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Allow passing a language version to `DartFomatter()`. Formatted code will be
44
parsed at that version. If omitted, defaults to the latest version. In a
55
future release, this parameter will become required.
6+
* Preserve type parameters on old-style function-typed formals that also use
7+
`this.` or `super.` (#1321).
68
* Remove temporary work around for analyzer 6.2.0 from dart_style 2.3.6.
79
* Require `package:analyzer` `>=6.5.0 <7.0.0`.
810

lib/src/short/source_visitor.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ class SourceVisitor extends ThrowingAstVisitor {
13391339
token(node.thisKeyword);
13401340
token(node.period);
13411341
token(node.name);
1342+
visit(node.typeParameters);
13421343
visit(node.parameters);
13431344
token(node.question);
13441345
_endFormalParameter(node);
@@ -2801,6 +2802,7 @@ class SourceVisitor extends ThrowingAstVisitor {
28012802
token(node.superKeyword);
28022803
token(node.period);
28032804
token(node.name);
2805+
visit(node.typeParameters);
28042806
visit(node.parameters);
28052807
token(node.question);
28062808
_endFormalParameter(node);

test/short/regression/1300/1321.unit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
>>> `super.` parameter.
2+
class A {
3+
A(int foo<T>(int a));
4+
}
5+
class B extends A {
6+
B.sub1(int super.bar1<T1>(int a1),);
7+
B.sub2(int super.bar2<T2>(int a2),);
8+
}
9+
main() {}
10+
<<<
11+
class A {
12+
A(int foo<T>(int a));
13+
}
14+
15+
class B extends A {
16+
B.sub1(
17+
int super.bar1<T1>(int a1),
18+
);
19+
B.sub2(
20+
int super.bar2<T2>(int a2),
21+
);
22+
}
23+
24+
main() {}
25+
>>> `this.` parameter.
26+
class A {
27+
A.sub1(int this.bar1<T1>(int a1),);
28+
A.sub2(int this.bar2<T2>(int a2),);
29+
}
30+
<<<
31+
class A {
32+
A.sub1(
33+
int this.bar1<T1>(int a1),
34+
);
35+
A.sub2(
36+
int this.bar2<T2>(int a2),
37+
);
38+
}

test/tall/regression/1300/1321.unit

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
>>> `super.` parameter.
2+
class A {
3+
A(int foo<T>(int a));
4+
}
5+
class B extends A {
6+
B.sub1(int super.bar1<T1>(int a1),);
7+
B.sub2(int super.bar2<T2>(int a2),);
8+
}
9+
main() {}
10+
<<<
11+
class A {
12+
A(int foo<T>(int a));
13+
}
14+
15+
class B extends A {
16+
B.sub1(int super.bar1<T1>(int a1));
17+
B.sub2(int super.bar2<T2>(int a2));
18+
}
19+
20+
main() {}
21+
>>> `this.` parameter.
22+
class A {
23+
A.sub1(int this.bar1<T1>(int a1),);
24+
A.sub2(int this.bar2<T2>(int a2),);
25+
}
26+
<<<
27+
class A {
28+
A.sub1(int this.bar1<T1>(int a1));
29+
A.sub2(int this.bar2<T2>(int a2));
30+
}

0 commit comments

Comments
 (0)