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

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

Issue 1160673003: fixes #202, check IndexExpression (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « lib/runtime/dart/collection.js ('k') | test/checker/checker_test.dart » ('j') | 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) 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // Dynamic invocation 712 // Dynamic invocation
713 // TODO(vsm): Move this logic to the resolver? 713 // TODO(vsm): Move this logic to the resolver?
714 if (op.type != TokenType.EQ_EQ && op.type != TokenType.BANG_EQ) { 714 if (op.type != TokenType.EQ_EQ && op.type != TokenType.BANG_EQ) {
715 _recordDynamicInvoke(node); 715 _recordDynamicInvoke(node);
716 } 716 }
717 } else { 717 } else {
718 var element = node.staticElement; 718 var element = node.staticElement;
719 // Method invocation. 719 // Method invocation.
720 if (element is MethodElement) { 720 if (element is MethodElement) {
721 var type = element.type as FunctionType; 721 var type = element.type as FunctionType;
722 assert(type.normalParameterTypes.length == 1); 722 // Analyzer should enforce number of parameter types, but check in
723 node.rightOperand = 723 // case we have erroneous input.
724 checkArgument(node.rightOperand, type.normalParameterTypes[0]); 724 if (type.normalParameterTypes.isNotEmpty) {
725 node.rightOperand =
726 checkArgument(node.rightOperand, type.normalParameterTypes[0]);
727 }
725 } else { 728 } else {
726 // TODO(vsm): Assert that the analyzer found an error here? 729 // TODO(vsm): Assert that the analyzer found an error here?
727 } 730 }
728 } 731 }
729 } else { 732 } else {
730 // Non-method operator. 733 // Non-method operator.
731 switch (op.type) { 734 switch (op.type) {
732 case TokenType.AMPERSAND_AMPERSAND: 735 case TokenType.AMPERSAND_AMPERSAND:
733 case TokenType.BAR_BAR: 736 case TokenType.BAR_BAR:
734 var boolType = _rules.provider.boolType; 737 var boolType = _rules.provider.boolType;
735 node.leftOperand = checkArgument(node.leftOperand, boolType); 738 node.leftOperand = checkArgument(node.leftOperand, boolType);
736 node.rightOperand = checkArgument(node.rightOperand, boolType); 739 node.rightOperand = checkArgument(node.rightOperand, boolType);
737 break; 740 break;
738 case TokenType.BANG_EQ: 741 case TokenType.BANG_EQ:
739 break; 742 break;
740 default: 743 default:
741 assert(false); 744 assert(false);
742 } 745 }
743 } 746 }
744 node.visitChildren(this); 747 node.visitChildren(this);
745 } 748 }
746 749
750 @override
751 void visitIndexExpression(IndexExpression node) {
752 if (_rules.isDynamicTarget(node.target)) {
753 _recordDynamicInvoke(node);
754 } else {
755 var element = node.staticElement;
756 if (element is MethodElement) {
757 var type = element.type as FunctionType;
758 // Analyzer should enforce number of parameter types, but check in
759 // case we have erroneous input.
760 if (type.normalParameterTypes.isNotEmpty) {
761 node.index = checkArgument(node.index, type.normalParameterTypes[0]);
762 }
763 } else {
764 // TODO(vsm): Assert that the analyzer found an error here?
765 }
766 }
767 node.visitChildren(this);
768 }
769
747 DartType getType(TypeName name) { 770 DartType getType(TypeName name) {
748 return (name == null) ? _rules.provider.dynamicType : name.type; 771 return (name == null) ? _rules.provider.dynamicType : name.type;
749 } 772 }
750 773
751 Expression checkAssignment(Expression expr, DartType type) { 774 Expression checkAssignment(Expression expr, DartType type) {
752 if (expr is ParenthesizedExpression) { 775 if (expr is ParenthesizedExpression) {
753 expr.expression = checkAssignment(expr.expression, type); 776 expr.expression = checkAssignment(expr.expression, type);
754 } else { 777 } else {
755 final staticInfo = _rules.checkAssignment(expr, type, _constantContext); 778 final staticInfo = _rules.checkAssignment(expr, type, _constantContext);
756 _recordMessage(staticInfo); 779 _recordMessage(staticInfo);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 void _recordDynamicInvoke(AstNode node) { 863 void _recordDynamicInvoke(AstNode node) {
841 _reporter.log(new DynamicInvoke(_rules, node)); 864 _reporter.log(new DynamicInvoke(_rules, node));
842 } 865 }
843 866
844 void _recordMessage(StaticInfo info) { 867 void _recordMessage(StaticInfo info) {
845 if (info == null) return; 868 if (info == null) return;
846 if (info.level >= logger.Level.SEVERE) _failure = true; 869 if (info.level >= logger.Level.SEVERE) _failure = true;
847 _reporter.log(info); 870 _reporter.log(info);
848 } 871 }
849 } 872 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/collection.js ('k') | test/checker/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698