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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/inferrer/inferrer_visitor.dart

Issue 182373002: Fix bad type-inferrence for logical expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 inferrer_visitor; 5 library inferrer_visitor;
6 6
7 import '../dart2jslib.dart' hide Selector, TypedSelector; 7 import '../dart2jslib.dart' hide Selector, TypedSelector;
8 import '../dart_types.dart'; 8 import '../dart_types.dart';
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../tree/tree.dart'; 10 import '../tree/tree.dart';
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 } 835 }
836 } 836 }
837 837
838 T visitOperatorSend(Send node) { 838 T visitOperatorSend(Send node) {
839 Operator op = node.selector; 839 Operator op = node.selector;
840 if ("[]" == op.source) { 840 if ("[]" == op.source) {
841 return visitDynamicSend(node); 841 return visitDynamicSend(node);
842 } else if ("&&" == op.source) { 842 } else if ("&&" == op.source) {
843 conditionIsSimple = false; 843 conditionIsSimple = false;
844 bool oldAccumulateIsChecks = accumulateIsChecks; 844 bool oldAccumulateIsChecks = accumulateIsChecks;
845 assert(accumulateIsChecks || isChecks == null);
845 accumulateIsChecks = true; 846 accumulateIsChecks = true;
846 if (isChecks == null) isChecks = <Send>[]; 847 if (isChecks == null) isChecks = <Send>[];
847 visit(node.receiver); 848 visit(node.receiver);
848 accumulateIsChecks = oldAccumulateIsChecks; 849 accumulateIsChecks = oldAccumulateIsChecks;
849 if (!accumulateIsChecks) isChecks = null; 850 if (!accumulateIsChecks) isChecks = null;
850 LocalsHandler<T> saved = locals; 851 LocalsHandler<T> saved = locals;
851 locals = new LocalsHandler<T>.from(locals, node); 852 locals = new LocalsHandler<T>.from(locals, node);
852 updateIsChecks(isChecks, usePositive: true); 853 updateIsChecks(isChecks, usePositive: true);
853 visit(node.arguments.head); 854 visit(node.arguments.head);
854 saved.mergeDiamondFlow(locals, null); 855 saved.mergeDiamondFlow(locals, null);
855 locals = saved; 856 locals = saved;
856 return types.boolType; 857 return types.boolType;
857 } else if ("||" == op.source) { 858 } else if ("||" == op.source) {
858 conditionIsSimple = false; 859 conditionIsSimple = false;
859 List<Send> tests = <Send>[]; 860 List<Send> tests = <Send>[];
860 handleCondition(node.receiver, tests); 861 handleCondition(node.receiver, tests);
861 LocalsHandler<T> saved = locals; 862 LocalsHandler<T> saved = locals;
862 locals = new LocalsHandler<T>.from(locals, node); 863 locals = new LocalsHandler<T>.from(locals, node);
863 updateIsChecks(tests, usePositive: false); 864 updateIsChecks(tests, usePositive: false);
864 bool oldAccumulateIsChecks = accumulateIsChecks; 865 bool oldAccumulateIsChecks = accumulateIsChecks;
865 accumulateIsChecks = false; 866 accumulateIsChecks = false;
867 isChecks = null;
ngeoffray 2014/02/27 10:33:12 How about an abstraction: bool stopAccumulatingIs
floitsch 2014/02/27 16:07:08 Added helper. Changed the assert from the '&&' in
866 visit(node.arguments.head); 868 visit(node.arguments.head);
867 accumulateIsChecks = oldAccumulateIsChecks; 869 accumulateIsChecks = oldAccumulateIsChecks;
868 saved.mergeDiamondFlow(locals, null); 870 saved.mergeDiamondFlow(locals, null);
869 locals = saved; 871 locals = saved;
870 return types.boolType; 872 return types.boolType;
871 } else if ("!" == op.source) { 873 } else if ("!" == op.source) {
872 bool oldAccumulateIsChecks = accumulateIsChecks; 874 bool oldAccumulateIsChecks = accumulateIsChecks;
873 accumulateIsChecks = false; 875 accumulateIsChecks = false;
floitsch 2014/02/27 16:07:08 Similar bug. (fixed in latest patch-set).
874 node.visitChildren(this); 876 node.visitChildren(this);
875 accumulateIsChecks = oldAccumulateIsChecks; 877 accumulateIsChecks = oldAccumulateIsChecks;
876 return types.boolType; 878 return types.boolType;
877 } else if ("is" == op.source) { 879 } else if ("is" == op.source) {
878 potentiallyAddIsCheck(node); 880 potentiallyAddIsCheck(node);
879 node.visitChildren(this); 881 node.visitChildren(this);
880 return types.boolType; 882 return types.boolType;
881 } else if ("as" == op.source) { 883 } else if ("as" == op.source) {
882 T receiverType = visit(node.receiver); 884 T receiverType = visit(node.receiver);
883 DartType type = elements.getType(node.arguments.head); 885 DartType type = elements.getType(node.arguments.head);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 return type; 1208 return type;
1207 } 1209 }
1208 1210
1209 T visitCascade(Cascade node) { 1211 T visitCascade(Cascade node) {
1210 // Ignore the result of the cascade send and return the type of the cascade 1212 // Ignore the result of the cascade send and return the type of the cascade
1211 // receiver. 1213 // receiver.
1212 visit(node.expression); 1214 visit(node.expression);
1213 return cascadeReceiverStack.removeLast(); 1215 return cascadeReceiverStack.removeLast();
1214 } 1216 }
1215 } 1217 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/simple_inferrer_and_or_test.dart » ('j') | tests/language/logical_expression2_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698