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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1036233006: Issue 20144. Reset propagated type if one of the 'if' branches changes it to a different one. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 12731 matching lines...) Expand 10 before | Expand all | Expand 10 after
12742 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 12742 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
12743 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 12743 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
12744 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 12744 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
12745 expect(propagatedType.element, same(typeProvider.mapType.element)); 12745 expect(propagatedType.element, same(typeProvider.mapType.element));
12746 List<DartType> typeArguments = propagatedType.typeArguments; 12746 List<DartType> typeArguments = propagatedType.typeArguments;
12747 expect(typeArguments, hasLength(2)); 12747 expect(typeArguments, hasLength(2));
12748 expect(typeArguments[0], same(typeProvider.dynamicType)); 12748 expect(typeArguments[0], same(typeProvider.dynamicType));
12749 expect(typeArguments[1], same(typeProvider.dynamicType)); 12749 expect(typeArguments[1], same(typeProvider.dynamicType));
12750 } 12750 }
12751 12751
12752 void test_mergePropagatedTypes_afterIfThen_different() {
12753 _assertTypeOfMarkedExpression(r'''
12754 main() {
12755 var v = 0;
12756 if (v != null) {
12757 v = '';
12758 }
12759 return v; // marker
12760 }''', null, null);
12761 }
12762
12763 void test_mergePropagatedTypes_afterIfThen_same() {
12764 _assertTypeOfMarkedExpression(r'''
12765 main() {
12766 var v = 1;
12767 if (v != null) {
12768 v = 2;
12769 }
12770 return v; // marker
12771 }''', null, typeProvider.intType);
12772 }
12773
12774 void test_mergePropagatedTypes_afterIfThenElse_different() {
12775 _assertTypeOfMarkedExpression(r'''
12776 main() {
12777 var v = 1;
12778 if (v != null) {
12779 v = 2;
12780 } else {
12781 v = '3';
12782 }
12783 return v; // marker
12784 }''', null, null);
12785 }
12786
12787 void test_mergePropagatedTypes_afterIfThenElse_same() {
12788 _assertTypeOfMarkedExpression(r'''
12789 main() {
12790 var v = 1;
12791 if (v != null) {
12792 v = 2;
12793 } else {
12794 v = 3;
12795 }
12796 return v; // marker
12797 }''', null, typeProvider.intType);
12798 }
12799
12752 void test_mergePropagatedTypesAtJoinPoint_4() { 12800 void test_mergePropagatedTypesAtJoinPoint_4() {
12753 // https://code.google.com/p/dart/issues/detail?id=19929 12801 // https://code.google.com/p/dart/issues/detail?id=19929
12754 _assertTypeOfMarkedExpression(r''' 12802 _assertTypeOfMarkedExpression(r'''
12755 f5(x) { 12803 f5(x) {
12756 var y = []; 12804 var y = [];
12757 if (x) { 12805 if (x) {
12758 y = 0; 12806 y = 0;
12759 } else { 12807 } else {
12760 return y; 12808 return y;
12761 } 12809 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
13000 * @param expectedStaticType if non-null, check actual static type is equal to this. 13048 * @param expectedStaticType if non-null, check actual static type is equal to this.
13001 * @param expectedPropagatedType if non-null, check actual static type is equa l to this. 13049 * @param expectedPropagatedType if non-null, check actual static type is equa l to this.
13002 * @throws Exception 13050 * @throws Exception
13003 */ 13051 */
13004 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, 13052 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType,
13005 DartType expectedPropagatedType) { 13053 DartType expectedPropagatedType) {
13006 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); 13054 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker");
13007 if (expectedStaticType != null) { 13055 if (expectedStaticType != null) {
13008 expect(identifier.staticType, expectedStaticType); 13056 expect(identifier.staticType, expectedStaticType);
13009 } 13057 }
13010 if (expectedPropagatedType != null) { 13058 expect(identifier.propagatedType, expectedPropagatedType);
13011 expect(identifier.propagatedType, expectedPropagatedType);
13012 }
13013 } 13059 }
13014 13060
13015 /** 13061 /**
13016 * Return the `SimpleIdentifier` marked by `marker`. The source code must have no 13062 * Return the `SimpleIdentifier` marked by `marker`. The source code must have no
13017 * errors and be verifiable. 13063 * errors and be verifiable.
13018 * 13064 *
13019 * @param code source code to analyze. 13065 * @param code source code to analyze.
13020 * @param marker marker identifying sought after expression in source code. 13066 * @param marker marker identifying sought after expression in source code.
13021 * @return expression marked by the marker. 13067 * @return expression marked by the marker.
13022 * @throws Exception 13068 * @throws Exception
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
13688 // check propagated type 13734 // check propagated type
13689 FunctionType propagatedType = node.propagatedType as FunctionType; 13735 FunctionType propagatedType = node.propagatedType as FunctionType;
13690 expect(propagatedType.returnType, test.typeProvider.stringType); 13736 expect(propagatedType.returnType, test.typeProvider.stringType);
13691 } on AnalysisException catch (e, stackTrace) { 13737 } on AnalysisException catch (e, stackTrace) {
13692 thrownException[0] = new CaughtException(e, stackTrace); 13738 thrownException[0] = new CaughtException(e, stackTrace);
13693 } 13739 }
13694 } 13740 }
13695 return null; 13741 return null;
13696 } 13742 }
13697 } 13743 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698