Skip to content

Commit

Permalink
Preserve type parameters in function-typed "this." and "super." params.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
munificent committed Aug 8, 2024
1 parent 1536c11 commit cfda44b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/short/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ class SourceVisitor extends ThrowingAstVisitor {
token(node.thisKeyword);
token(node.period);
token(node.name);
visit(node.typeParameters);
visit(node.parameters);
token(node.question);
_endFormalParameter(node);
Expand Down Expand Up @@ -2801,6 +2802,7 @@ class SourceVisitor extends ThrowingAstVisitor {
token(node.superKeyword);
token(node.period);
token(node.name);
visit(node.typeParameters);
visit(node.parameters);
token(node.question);
_endFormalParameter(node);
Expand Down
38 changes: 38 additions & 0 deletions test/short/regression/1300/1321.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
>>> `super.` parameter.
class A {
A(int foo<T>(int a));
}
class B extends A {
B.sub1(int super.bar1<T1>(int a1),);
B.sub2(int super.bar2<T2>(int a2),);
}
main() {}
<<<
class A {
A(int foo<T>(int a));
}

class B extends A {
B.sub1(
int super.bar1<T1>(int a1),
);
B.sub2(
int super.bar2<T2>(int a2),
);
}

main() {}
>>> `this.` parameter.
class A {
A.sub1(int this.bar1<T1>(int a1),);
A.sub2(int this.bar2<T2>(int a2),);
}
<<<
class A {
A.sub1(
int this.bar1<T1>(int a1),
);
A.sub2(
int this.bar2<T2>(int a2),
);
}
30 changes: 30 additions & 0 deletions test/tall/regression/1300/1321.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
>>> `super.` parameter.
class A {
A(int foo<T>(int a));
}
class B extends A {
B.sub1(int super.bar1<T1>(int a1),);
B.sub2(int super.bar2<T2>(int a2),);
}
main() {}
<<<
class A {
A(int foo<T>(int a));
}

class B extends A {
B.sub1(int super.bar1<T1>(int a1));
B.sub2(int super.bar2<T2>(int a2));
}

main() {}
>>> `this.` parameter.
class A {
A.sub1(int this.bar1<T1>(int a1),);
A.sub2(int this.bar2<T2>(int a2),);
}
<<<
class A {
A.sub1(int this.bar1<T1>(int a1));
A.sub2(int this.bar2<T2>(int a2));
}

0 comments on commit cfda44b

Please sign in to comment.