Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: pkg/kernel/lib/type_checker.dart

Issue 2876533004: Add FunctionType.getNamedParameter. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« pkg/kernel/lib/ast.dart ('K') | « pkg/kernel/lib/ast.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 Substitution.fromPairs(function.typeParameters, arguments.types); 490 Substitution.fromPairs(function.typeParameters, arguments.types);
491 for (int i = 0; i < arguments.positional.length; ++i) { 491 for (int i = 0; i < arguments.positional.length; ++i) {
492 var expectedType = instantiation.substituteType( 492 var expectedType = instantiation.substituteType(
493 function.positionalParameters[i], 493 function.positionalParameters[i],
494 contravariant: true); 494 contravariant: true);
495 arguments.positional[i] = 495 arguments.positional[i] =
496 checkAndDowncastExpression(arguments.positional[i], expectedType); 496 checkAndDowncastExpression(arguments.positional[i], expectedType);
497 } 497 }
498 for (int i = 0; i < arguments.named.length; ++i) { 498 for (int i = 0; i < arguments.named.length; ++i) {
499 var argument = arguments.named[i]; 499 var argument = arguments.named[i];
500 bool found = false; 500 var parameterType = function.getNamedParameter(argument.name);
501 for (int j = 0; j < function.namedParameters.length; ++j) { 501 if (parameterType != null) {
502 if (argument.name == function.namedParameters[j].name) { 502 var expectedType =
503 var expectedType = instantiation.substituteType( 503 instantiation.substituteType(parameterType, contravariant: true);
504 function.namedParameters[j].type, 504 argument.value =
505 contravariant: true); 505 checkAndDowncastExpression(argument.value, expectedType);
506 argument.value = 506 } else {
507 checkAndDowncastExpression(argument.value, expectedType);
508 found = true;
509 break;
510 }
511 }
512 if (!found) {
513 fail(argument.value, 'Unexpected named parameter: ${argument.name}'); 507 fail(argument.value, 'Unexpected named parameter: ${argument.name}');
514 return const BottomType(); 508 return const BottomType();
515 } 509 }
516 } 510 }
517 return instantiation.substituteType(function.returnType); 511 return instantiation.substituteType(function.returnType);
518 } 512 }
519 513
520 @override 514 @override
521 DartType visitMethodInvocation(MethodInvocation node) { 515 DartType visitMethodInvocation(MethodInvocation node) {
522 var target = node.interfaceTarget; 516 var target = node.interfaceTarget;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 } 949 }
956 950
957 @override 951 @override
958 visitLocalInitializer(LocalInitializer node) { 952 visitLocalInitializer(LocalInitializer node) {
959 visitVariableDeclaration(node.variable); 953 visitVariableDeclaration(node.variable);
960 } 954 }
961 955
962 @override 956 @override
963 visitInvalidInitializer(InvalidInitializer node) {} 957 visitInvalidInitializer(InvalidInitializer node) {}
964 } 958 }
OLDNEW
« pkg/kernel/lib/ast.dart ('K') | « pkg/kernel/lib/ast.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698