[cfe] Implement a formal list helper as an extension method

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/405006

Change-Id: Ic3c2c5a572beda06c511a4bfc25cd1526f1b09d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404825
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
diff --git a/pkg/front_end/lib/src/source/source_constructor_builder.dart b/pkg/front_end/lib/src/source/source_constructor_builder.dart
index a43afef..8a213b1 100644
--- a/pkg/front_end/lib/src/source/source_constructor_builder.dart
+++ b/pkg/front_end/lib/src/source/source_constructor_builder.dart
@@ -880,7 +880,7 @@
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (_hasBuiltOutlines) return;
 
-    inferFormals(formals, classHierarchy);
+    formals?.infer(classHierarchy);
 
     if (isConst && isAugmenting) {
       origin.buildOutlineExpressions(
diff --git a/pkg/front_end/lib/src/source/source_factory_builder.dart b/pkg/front_end/lib/src/source/source_factory_builder.dart
index 6675afe..876aa71 100644
--- a/pkg/front_end/lib/src/source/source_factory_builder.dart
+++ b/pkg/front_end/lib/src/source/source_factory_builder.dart
@@ -263,7 +263,7 @@
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (_hasBuiltOutlines) return;
 
-    inferFormals(formals, classHierarchy);
+    formals?.infer(classHierarchy);
 
     if (_delayedDefaultValueCloner != null) {
       delayedDefaultValueCloners.add(_delayedDefaultValueCloner!);
@@ -563,7 +563,7 @@
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (_hasBuiltOutlines) return;
 
-    inferFormals(formals, classHierarchy);
+    formals?.infer(classHierarchy);
 
     if (isConst && isAugmenting) {
       origin.buildOutlineExpressions(
diff --git a/pkg/front_end/lib/src/source/source_function_builder.dart b/pkg/front_end/lib/src/source/source_function_builder.dart
index 9448c14..1763ba9 100644
--- a/pkg/front_end/lib/src/source/source_function_builder.dart
+++ b/pkg/front_end/lib/src/source/source_function_builder.dart
@@ -423,7 +423,7 @@
   void buildOutlineExpressions(ClassHierarchy classHierarchy,
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (!hasBuiltOutlineExpressions) {
-      inferFormals(formals, classHierarchy);
+      formals?.infer(classHierarchy);
 
       DeclarationBuilder? classOrExtensionBuilder =
           isClassMember || isExtensionMember || isExtensionTypeMember
@@ -575,11 +575,10 @@
       ]);
 }
 
-/// Ensures the type of each of the [formals] is inferred.
-void inferFormals(
-    List<FormalParameterBuilder>? formals, ClassHierarchy classHierarchy) {
-  if (formals != null) {
-    for (FormalParameterBuilder formal in formals) {
+extension FormalsMethods on List<FormalParameterBuilder> {
+  /// Ensures the type of each of the formals is inferred.
+  void infer(ClassHierarchy classHierarchy) {
+    for (FormalParameterBuilder formal in this) {
       TypeBuilder formalType = formal.type;
       if (formalType is InferableTypeBuilder) {
         formalType.inferType(classHierarchy);
diff --git a/pkg/front_end/test/coverage_suite_expected.dart b/pkg/front_end/test/coverage_suite_expected.dart
index 725798a..b7ef20e 100644
--- a/pkg/front_end/test/coverage_suite_expected.dart
+++ b/pkg/front_end/test/coverage_suite_expected.dart
@@ -920,7 +920,7 @@
   ),
   // 100.0%.
   "package:front_end/src/source/source_constructor_builder.dart": (
-    hitCount: 891,
+    hitCount: 893,
     missCount: 0,
   ),
   // 100.0%.
@@ -941,13 +941,13 @@
   ),
   // 100.0%.
   "package:front_end/src/source/source_factory_builder.dart": (
-    hitCount: 593,
+    hitCount: 590,
     missCount: 0,
   ),
-  // 100.0%.
+  // 99.60317460317461%.
   "package:front_end/src/source/source_function_builder.dart": (
-    hitCount: 243,
-    missCount: 0,
+    hitCount: 251,
+    missCount: 1,
   ),
   // 100.0%.
   "package:front_end/src/source/source_library_builder.dart": (