Recover from default values in function types

Fixes https://github.com/dart-lang/sdk/issues/35035

Change-Id: I29fe0d792998c43f49877d97b61b3afc16c43cef
Reviewed-on: https://dart-review.googlesource.com/c/82984
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Auto-Submit: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index a3d119d..090af34 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -2681,8 +2681,12 @@
   void handleValuedFormalParameter(Token equals, Token token) {
     debugEvent("ValuedFormalParameter");
     Expression initializer = popForValue();
-    Identifier name = pop();
-    push(new InitializedIdentifier(name, initializer));
+    Object name = pop();
+    if (name is ParserRecovery) {
+      push(name);
+    } else {
+      push(new InitializedIdentifier(name, initializer));
+    }
   }
 
   @override
diff --git a/pkg/front_end/lib/src/fasta/source/stack_listener.dart b/pkg/front_end/lib/src/fasta/source/stack_listener.dart
index 34dc2c8..ea5e9b7 100644
--- a/pkg/front_end/lib/src/fasta/source/stack_listener.dart
+++ b/pkg/front_end/lib/src/fasta/source/stack_listener.dart
@@ -494,5 +494,5 @@
   final int charOffset;
   ParserRecovery(this.charOffset);
 
-  String toString() => "ParserRecovery(charOffset)";
+  String toString() => "ParserRecovery(@$charOffset)";
 }
diff --git a/pkg/front_end/testcases/function_type_default_value.dart b/pkg/front_end/testcases/function_type_default_value.dart
new file mode 100644
index 0000000..30536ed
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart
@@ -0,0 +1,7 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+void Function({obj: Object}) x;
+
+main() {}
diff --git a/pkg/front_end/testcases/function_type_default_value.dart.direct.expect b/pkg/front_end/testcases/function_type_default_value.dart.direct.expect
new file mode 100644
index 0000000..ba53ef3
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart.direct.expect
@@ -0,0 +1,29 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:16: Warning: 'obj' isn't a type.
+// void Function({obj: Object}) x;
+//                ^^^
+
+// Unhandled errors:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+
+library;
+import self as self;
+
+static field () → void x;
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/function_type_default_value.dart.direct.transformed.expect b/pkg/front_end/testcases/function_type_default_value.dart.direct.transformed.expect
new file mode 100644
index 0000000..1e5f712
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart.direct.transformed.expect
@@ -0,0 +1,15 @@
+// Unhandled errors:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+
+library;
+import self as self;
+
+static field () → void x;
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/function_type_default_value.dart.outline.expect b/pkg/front_end/testcases/function_type_default_value.dart.outline.expect
new file mode 100644
index 0000000..8512a58
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart.outline.expect
@@ -0,0 +1,16 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+
+library;
+import self as self;
+
+static field () → void x;
+static method main() → dynamic
+  ;
diff --git a/pkg/front_end/testcases/function_type_default_value.dart.strong.expect b/pkg/front_end/testcases/function_type_default_value.dart.strong.expect
new file mode 100644
index 0000000..1d5c09e
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart.strong.expect
@@ -0,0 +1,33 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:16: Error: 'obj' isn't a type.
+// void Function({obj: Object}) x;
+//                ^^^
+
+// Unhandled errors:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:16: Error: 'obj' isn't a type.
+// void Function({obj: Object}) x;
+//                ^^^
+
+library;
+import self as self;
+
+static field () → void x;
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/function_type_default_value.dart.strong.transformed.expect b/pkg/front_end/testcases/function_type_default_value.dart.strong.transformed.expect
new file mode 100644
index 0000000..de199db
--- /dev/null
+++ b/pkg/front_end/testcases/function_type_default_value.dart.strong.transformed.expect
@@ -0,0 +1,19 @@
+// Unhandled errors:
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Expected an identifier, but got ':'.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:19: Error: Can't have a default value in a function type.
+// void Function({obj: Object}) x;
+//                   ^
+//
+// pkg/front_end/testcases/function_type_default_value.dart:5:16: Error: 'obj' isn't a type.
+// void Function({obj: Object}) x;
+//                ^^^
+
+library;
+import self as self;
+
+static field () → void x;
+static method main() → dynamic {}