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>
This commit is contained in:
Peter von der Ahé 2018-11-06 11:39:32 +00:00 committed by commit-bot@chromium.org
parent 0fd14324c5
commit 0fd4a51e2c
8 changed files with 126 additions and 3 deletions

View file

@ -2686,8 +2686,12 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
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

View file

@ -494,5 +494,5 @@ class ParserRecovery {
final int charOffset;
ParserRecovery(this.charOffset);
String toString() => "ParserRecovery(charOffset)";
String toString() => "ParserRecovery(@$charOffset)";
}

View file

@ -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() {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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
;

View file

@ -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 {}

View file

@ -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 {}