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

Side by Side Diff: lib/src/checker/checker.dart

Issue 1055923002: Don't call dinvoke on Object methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: modify test Created 5 years, 8 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 4
5 library dev_compiler.src.checker.checker; 5 library dev_compiler.src.checker.checker;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType; 10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType;
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 var entries = node.entries; 449 var entries = node.entries;
450 for (int i = 0; i < entries.length; i++) { 450 for (int i = 0; i < entries.length; i++) {
451 var entry = entries[i]; 451 var entry = entries[i];
452 entry.key = checkArgument(entry.key, ktype); 452 entry.key = checkArgument(entry.key, ktype);
453 entry.value = checkArgument(entry.value, vtype); 453 entry.value = checkArgument(entry.value, vtype);
454 } 454 }
455 super.visitMapLiteral(node); 455 super.visitMapLiteral(node);
456 } 456 }
457 457
458 // Check invocations 458 // Check invocations
459 bool checkArgumentList(ArgumentList node, FunctionType type) { 459 bool checkArgumentList(ArgumentList node, DartType type) {
460 NodeList<Expression> list = node.arguments; 460 NodeList<Expression> list = node.arguments;
461 int len = list.length; 461 int len = list.length;
462 if (len == 0) return true;
463 FunctionType ft = type;
462 for (int i = 0; i < len; ++i) { 464 for (int i = 0; i < len; ++i) {
463 Expression arg = list[i]; 465 Expression arg = list[i];
464 ParameterElement element = node.getStaticParameterElementFor(arg); 466 ParameterElement element = node.getStaticParameterElementFor(arg);
465 if (element == null) { 467 if (element == null) {
466 if (type.parameters.length < len) { 468 if (ft.parameters.length < len) {
467 // We found an argument mismatch, the analyzer will report this too, 469 // We found an argument mismatch, the analyzer will report this too,
468 // so no need to insert an error for this here. 470 // so no need to insert an error for this here.
469 continue; 471 continue;
470 } 472 }
471 element = type.parameters[i]; 473 element = ft.parameters[i];
472 // TODO(vsm): When can this happen? 474 // TODO(vsm): When can this happen?
473 assert(element != null); 475 assert(element != null);
474 } 476 }
475 DartType expectedType = _rules.elementType(element); 477 DartType expectedType = _rules.elementType(element);
476 if (expectedType == null) expectedType = _rules.provider.dynamicType; 478 if (expectedType == null) expectedType = _rules.provider.dynamicType;
477 list[i] = checkArgument(arg, expectedType); 479 list[i] = checkArgument(arg, expectedType);
478 } 480 }
479 return true; 481 return true;
480 } 482 }
481 483
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 node.expression = _checkReturn(node.expression, node); 561 node.expression = _checkReturn(node.expression, node);
560 node.visitChildren(this); 562 node.visitChildren(this);
561 } 563 }
562 564
563 visitReturnStatement(ReturnStatement node) { 565 visitReturnStatement(ReturnStatement node) {
564 node.expression = _checkReturn(node.expression, node); 566 node.expression = _checkReturn(node.expression, node);
565 node.visitChildren(this); 567 node.visitChildren(this);
566 } 568 }
567 569
568 visitPropertyAccess(PropertyAccess node) { 570 visitPropertyAccess(PropertyAccess node) {
569 if (_rules.isDynamicGet(node.realTarget)) { 571 if (_rules.isDynamicGet(node.realTarget, node.propertyName.name)) {
570 _recordDynamicInvoke(node); 572 _recordDynamicInvoke(node);
571 } 573 }
572 node.visitChildren(this); 574 node.visitChildren(this);
573 } 575 }
574 576
575 visitPrefixedIdentifier(PrefixedIdentifier node) { 577 visitPrefixedIdentifier(PrefixedIdentifier node) {
576 final target = node.prefix; 578 final target = node.prefix;
577 // Check if the prefix is a library - PrefixElement denotes a library 579 // Check if the prefix is a library - PrefixElement denotes a library
578 // access. 580 // access.
579 if (target.staticElement is! PrefixElement && _rules.isDynamicGet(target)) { 581 if (target.staticElement is! PrefixElement &&
582 _rules.isDynamicGet(target, node.identifier.name)) {
580 _recordDynamicInvoke(node); 583 _recordDynamicInvoke(node);
581 } 584 }
582 node.visitChildren(this); 585 node.visitChildren(this);
583 } 586 }
584 587
585 @override visitDefaultFormalParameter(DefaultFormalParameter node) { 588 @override visitDefaultFormalParameter(DefaultFormalParameter node) {
586 _visitMaybeConst(node, (node) { 589 _visitMaybeConst(node, (node) {
587 // Check that defaults have the proper subtype. 590 // Check that defaults have the proper subtype.
588 var parameter = node.parameter; 591 var parameter = node.parameter;
589 var parameterType = _rules.elementType(parameter.element); 592 var parameterType = _rules.elementType(parameter.element);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 void _recordDynamicInvoke(AstNode node) { 795 void _recordDynamicInvoke(AstNode node) {
793 _reporter.log(new DynamicInvoke(_rules, node)); 796 _reporter.log(new DynamicInvoke(_rules, node));
794 } 797 }
795 798
796 void _recordMessage(StaticInfo info) { 799 void _recordMessage(StaticInfo info) {
797 if (info == null) return; 800 if (info == null) return;
798 if (info.level >= logger.Level.SEVERE) _failure = true; 801 if (info.level >= logger.Level.SEVERE) _failure = true;
799 _reporter.log(info); 802 _reporter.log(info);
800 } 803 }
801 } 804 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698