Don't crash on during indexing references to named parameters of a generic function types.

R=brianwilkerson@google.com

Change-Id: I0da0b1785d7dab2c7c84527317e542b7ef718bd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart
index 61b116e..1c23029 100644
--- a/pkg/analyzer/lib/src/dart/analysis/index.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/index.dart
@@ -487,6 +487,14 @@
             element.enclosingElement.isSynthetic)) {
       return;
     }
+    // Elements for generic function types are enclosed by the compilation
+    // units, but don't have names. So, we cannot index references to their
+    // named parameters. Ignore them.
+    if (elementKind == ElementKind.PARAMETER &&
+        element is ParameterElement &&
+        element.enclosingElement is GenericFunctionTypeElement) {
+      return;
+    }
     // Add the relation.
     assembler.addElementRelation(element, kind, offset, length, isQualified);
   }
diff --git a/pkg/analyzer/test/src/dart/analysis/index_test.dart b/pkg/analyzer/test/src/dart/analysis/index_test.dart
index a4217fe..56fb0c4 100644
--- a/pkg/analyzer/test/src/dart/analysis/index_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/index_test.dart
@@ -883,6 +883,19 @@
     assertThat(element)..isReferencedAt('p: 1', true);
   }
 
+  test_isReferencedBy_ParameterElement_genericFunctionType() async {
+    await _indexTestUnit('''
+typedef F = void Function({int p});
+
+void main() {
+  F f;
+  f(p: 0);
+}
+''');
+    // We should not crash because of reference to "p" - a named parameter
+    // of a generic function type.
+  }
+
   test_isReferencedBy_ParameterElement_optionalPositional() async {
     await _indexTestUnit('''
 foo([p]) {