Top-level getters do not have parameters

Change-Id: If8e079987f957538286afed162073fe4f323dea2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105469
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/dart/ast/ast.dart b/pkg/analyzer/lib/dart/ast/ast.dart
index a34b97c..14df41a 100644
--- a/pkg/analyzer/lib/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/dart/ast/ast.dart
@@ -2694,7 +2694,8 @@
   /// Set the element associated with the function to the given [element].
   void set element(ExecutableElement element);
 
-  /// Return the parameters associated with the function.
+  /// Return the parameters associated with the function, or `null` if the
+  /// function is part of a top-level getter.
   FormalParameterList get parameters;
 
   /// Set the parameters associated with the function to the given list of
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index df710e1..1d17498 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -4910,7 +4910,8 @@
   /// not a generic method.
   TypeParameterListImpl _typeParameters;
 
-  /// The parameters associated with the function.
+  /// The parameters associated with the function, or `null` if the function is
+  /// part of a top-level getter.
   FormalParameterListImpl _parameters;
 
   /// The body of the function, or `null` if this is an external function.
diff --git a/pkg/nnbd_migration/lib/src/graph_builder.dart b/pkg/nnbd_migration/lib/src/graph_builder.dart
index 0bd0aa8..cf3c46d 100644
--- a/pkg/nnbd_migration/lib/src/graph_builder.dart
+++ b/pkg/nnbd_migration/lib/src/graph_builder.dart
@@ -278,7 +278,7 @@
 
   @override
   DecoratedType visitFunctionDeclaration(FunctionDeclaration node) {
-    node.functionExpression.parameters.accept(this);
+    node.functionExpression.parameters?.accept(this);
     assert(_currentFunctionType == null);
     _currentFunctionType =
         _variables.decoratedElementType(node.declaredElement);
diff --git a/pkg/nnbd_migration/test/api_test.dart b/pkg/nnbd_migration/test/api_test.dart
index ca633bf..a7f3966 100644
--- a/pkg/nnbd_migration/test/api_test.dart
+++ b/pkg/nnbd_migration/test/api_test.dart
@@ -629,6 +629,16 @@
     await _checkSingleFileChanges(content, expected);
   }
 
+  test_getter_topLevel() async {
+    var content = '''
+int get g => 0;
+''';
+    var expected = '''
+int get g => 0;
+''';
+    await _checkSingleFileChanges(content, expected);
+  }
+
   test_named_parameter_no_default_unused() async {
     var content = '''
 void f({String s}) {}