| Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
|
| 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 21e00f59580a008ed96a87404c6527c78fbffda0..d9156ba62a4e80570c76c460d085c0c8c5a2d14d 100644
|
| --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
|
| +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
|
| @@ -1622,7 +1622,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
| if (target is Constructor) {
|
| typeParameters = target.enclosingClass.typeParameters;
|
| }
|
| - if (!checkArguments(target.function, arguments, typeParameters)) {
|
| + if (!addDefaultArguments(target.function, arguments, typeParameters)) {
|
| return throwNoSuchMethodError(target.name.name, arguments, charOffset);
|
| }
|
| if (target is Constructor) {
|
| @@ -1632,13 +1632,31 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
| }
|
| }
|
|
|
| - bool checkArguments(FunctionNode function, Arguments arguments,
|
| + bool addDefaultArguments(FunctionNode function, Arguments arguments,
|
| List<TypeParameter> typeParameters) {
|
| + bool missingInitializers = false;
|
| +
|
| + Expression defaultArgumentFrom(Expression expression) {
|
| + if (expression == null) {
|
| + missingInitializers = true;
|
| + return null;
|
| + }
|
| + cloner ??= new CloneVisitor();
|
| + return cloner.clone(expression);
|
| + }
|
|
|
| if (arguments.positional.length < function.requiredParameterCount ||
|
| arguments.positional.length > function.positionalParameters.length) {
|
| return false;
|
| }
|
| + for (int i = arguments.positional.length;
|
| + i < function.positionalParameters.length;
|
| + i++) {
|
| + var expression =
|
| + defaultArgumentFrom(function.positionalParameters[i].initializer);
|
| + expression?.parent = arguments;
|
| + arguments.positional.add(expression);
|
| + }
|
| Map<String, VariableDeclaration> names;
|
| if (function.namedParameters.isNotEmpty) {
|
| names = <String, VariableDeclaration>{};
|
| @@ -1655,6 +1673,14 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
| }
|
| }
|
| }
|
| + if (names != null) {
|
| + for (String name in names.keys) {
|
| + VariableDeclaration parameter = names[name];
|
| + arguments.named.add(new NamedExpression(
|
| + name, defaultArgumentFrom(parameter.initializer))
|
| + ..parent = arguments);
|
| + }
|
| + }
|
| if (typeParameters.length != arguments.types.length) {
|
| arguments.types.clear();
|
| for (int i = 0; i < typeParameters.length; i++) {
|
| @@ -1662,6 +1688,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
| }
|
| }
|
|
|
| + if (missingInitializers) {
|
| + library.addArgumentsWithMissingDefaultValues(arguments, function);
|
| + }
|
| return true;
|
| }
|
|
|
|
|