OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library kernel.type_checker; | 4 library kernel.type_checker; |
5 | 5 |
6 import 'ast.dart'; | 6 import 'ast.dart'; |
7 import 'class_hierarchy.dart'; | 7 import 'class_hierarchy.dart'; |
8 import 'core_types.dart'; | 8 import 'core_types.dart'; |
9 import 'type_algebra.dart'; | 9 import 'type_algebra.dart'; |
10 import 'type_environment.dart'; | 10 import 'type_environment.dart'; |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 var instantiation = | 464 var instantiation = |
465 Substitution.fromPairs(function.typeParameters, arguments.types); | 465 Substitution.fromPairs(function.typeParameters, arguments.types); |
466 for (int i = 0; i < arguments.positional.length; ++i) { | 466 for (int i = 0; i < arguments.positional.length; ++i) { |
467 var expectedType = instantiation.substituteType( | 467 var expectedType = instantiation.substituteType( |
468 function.positionalParameters[i], | 468 function.positionalParameters[i], |
469 contravariant: true); | 469 contravariant: true); |
470 checkAssignableExpression(arguments.positional[i], expectedType); | 470 checkAssignableExpression(arguments.positional[i], expectedType); |
471 } | 471 } |
472 for (int i = 0; i < arguments.named.length; ++i) { | 472 for (int i = 0; i < arguments.named.length; ++i) { |
473 var argument = arguments.named[i]; | 473 var argument = arguments.named[i]; |
474 var expectedType = function.namedParameters[argument.name]; | 474 bool found = false; |
475 if (expectedType == null) { | 475 for (int j = 0; j < function.namedParameters.length; ++j) { |
| 476 if (argument.name == function.namedParameters[j].name) { |
| 477 var expectedType = instantiation.substituteType( |
| 478 function.namedParameters[j].type, |
| 479 contravariant: true); |
| 480 checkAssignableExpression(argument.value, expectedType); |
| 481 found = true; |
| 482 break; |
| 483 } |
| 484 } |
| 485 if (!found) { |
476 fail(argument.value, 'Unexpected named parameter: ${argument.name}'); | 486 fail(argument.value, 'Unexpected named parameter: ${argument.name}'); |
477 } else { | 487 return const BottomType(); |
478 checkAssignableExpression(argument.value, | |
479 instantiation.substituteType(expectedType, contravariant: true)); | |
480 } | 488 } |
481 } | 489 } |
482 return instantiation.substituteType(function.returnType); | 490 return instantiation.substituteType(function.returnType); |
483 } | 491 } |
484 | 492 |
485 @override | 493 @override |
486 DartType visitMethodInvocation(MethodInvocation node) { | 494 DartType visitMethodInvocation(MethodInvocation node) { |
487 var target = node.interfaceTarget; | 495 var target = node.interfaceTarget; |
488 if (target == null) { | 496 if (target == null) { |
489 var receiver = visitExpression(node.receiver); | 497 var receiver = visitExpression(node.receiver); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 } | 854 } |
847 | 855 |
848 @override | 856 @override |
849 visitLocalInitializer(LocalInitializer node) { | 857 visitLocalInitializer(LocalInitializer node) { |
850 visitVariableDeclaration(node.variable); | 858 visitVariableDeclaration(node.variable); |
851 } | 859 } |
852 | 860 |
853 @override | 861 @override |
854 visitInvalidInitializer(InvalidInitializer node) {} | 862 visitInvalidInitializer(InvalidInitializer node) {} |
855 } | 863 } |
OLD | NEW |