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

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

Issue 905293003: Fix inference of the static type of an async function literal. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix incorrect comments Created 5 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
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_test.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 10012 matching lines...) Expand 10 before | Expand all | Expand 10 after
10023 _listener.assertNoErrors(); 10023 _listener.assertNoErrors();
10024 } 10024 }
10025 10025
10026 void test_visitDoubleLiteral() { 10026 void test_visitDoubleLiteral() {
10027 // 4.33 10027 // 4.33
10028 Expression node = AstFactory.doubleLiteral(4.33); 10028 Expression node = AstFactory.doubleLiteral(4.33);
10029 expect(_analyze(node), same(_typeProvider.doubleType)); 10029 expect(_analyze(node), same(_typeProvider.doubleType));
10030 _listener.assertNoErrors(); 10030 _listener.assertNoErrors();
10031 } 10031 }
10032 10032
10033 void test_visitFunctionExpression_async_block() {
10034 // () async {}
10035 InterfaceType intType = _typeProvider.intType;
10036 BlockFunctionBody body = AstFactory.blockFunctionBody2();
10037 body.keyword = TokenFactory.tokenFromString('async');
10038 FunctionExpression node =
10039 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10040 DartType resultType = _analyze(node);
10041 _assertFunctionType(
10042 _typeProvider.futureDynamicType,
10043 null,
10044 null,
10045 null,
10046 resultType);
10047 _listener.assertNoErrors();
10048 }
10049
10050 void test_visitFunctionExpression_async_expression() {
10051 // () async => e, where e has type int
10052 InterfaceType intType = _typeProvider.intType;
10053 InterfaceType futureIntType =
10054 _typeProvider.futureType.substitute4(<DartType>[intType]);
10055 Expression expression = _resolvedVariable(intType, 'e');
10056 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression);
10057 body.keyword = TokenFactory.tokenFromString('async');
10058 FunctionExpression node =
10059 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10060 DartType resultType = _analyze(node);
10061 _assertFunctionType(futureIntType, null, null, null, resultType);
10062 _listener.assertNoErrors();
10063 }
10064
10065 void test_visitFunctionExpression_async_expression_flatten() {
10066 // () async => e, where e has type Future<int>
10067 InterfaceType intType = _typeProvider.intType;
10068 InterfaceType futureIntType =
10069 _typeProvider.futureType.substitute4(<DartType>[intType]);
10070 Expression expression = _resolvedVariable(futureIntType, 'e');
10071 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression);
10072 body.keyword = TokenFactory.tokenFromString('async');
10073 FunctionExpression node =
10074 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10075 DartType resultType = _analyze(node);
10076 _assertFunctionType(futureIntType, null, null, null, resultType);
10077 _listener.assertNoErrors();
10078 }
10079
10080 void test_visitFunctionExpression_async_expression_flatten_twice() {
10081 // () async => e, where e has type Future<Future<int>>
10082 InterfaceType intType = _typeProvider.intType;
10083 InterfaceType futureIntType =
10084 _typeProvider.futureType.substitute4(<DartType>[intType]);
10085 InterfaceType futureFutureIntType =
10086 _typeProvider.futureType.substitute4(<DartType>[futureIntType]);
10087 Expression expression = _resolvedVariable(futureFutureIntType, 'e');
10088 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression);
10089 body.keyword = TokenFactory.tokenFromString('async');
10090 FunctionExpression node =
10091 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10092 DartType resultType = _analyze(node);
10093 _assertFunctionType(futureIntType, null, null, null, resultType);
10094 _listener.assertNoErrors();
10095 }
10096
10033 void test_visitFunctionExpression_generator_async() { 10097 void test_visitFunctionExpression_generator_async() {
10034 // () async* {} 10098 // () async* {}
10035 BlockFunctionBody body = AstFactory.blockFunctionBody2(); 10099 BlockFunctionBody body = AstFactory.blockFunctionBody2();
10036 body.keyword = TokenFactory.tokenFromString('async'); 10100 body.keyword = TokenFactory.tokenFromString('async');
10037 body.star = TokenFactory.tokenFromType(TokenType.STAR); 10101 body.star = TokenFactory.tokenFromType(TokenType.STAR);
10038 FunctionExpression node = 10102 FunctionExpression node =
10039 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); 10103 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10040 DartType resultType = _analyze(node); 10104 DartType resultType = _analyze(node);
10041 _assertFunctionType( 10105 _assertFunctionType(
10042 _typeProvider.streamDynamicType, 10106 _typeProvider.streamDynamicType,
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
10857 } 10921 }
10858 Map<String, DartType> namedTypes = functionType.namedParameterTypes; 10922 Map<String, DartType> namedTypes = functionType.namedParameterTypes;
10859 if (expectedNamedTypes == null) { 10923 if (expectedNamedTypes == null) {
10860 expect(namedTypes, hasLength(0)); 10924 expect(namedTypes, hasLength(0));
10861 } else { 10925 } else {
10862 expect(namedTypes, hasLength(expectedNamedTypes.length)); 10926 expect(namedTypes, hasLength(expectedNamedTypes.length));
10863 expectedNamedTypes.forEach((String name, DartType type) { 10927 expectedNamedTypes.forEach((String name, DartType type) {
10864 expect(namedTypes[name], same(type)); 10928 expect(namedTypes[name], same(type));
10865 }); 10929 });
10866 } 10930 }
10867 expect(functionType.returnType, same(expectedReturnType)); 10931 expect(functionType.returnType, equals(expectedReturnType));
10868 } 10932 }
10869 10933
10870 void _assertType(InterfaceTypeImpl expectedType, 10934 void _assertType(InterfaceTypeImpl expectedType,
10871 InterfaceTypeImpl actualType) { 10935 InterfaceTypeImpl actualType) {
10872 expect(actualType.displayName, expectedType.displayName); 10936 expect(actualType.displayName, expectedType.displayName);
10873 expect(actualType.element, expectedType.element); 10937 expect(actualType.element, expectedType.element);
10874 List<DartType> expectedArguments = expectedType.typeArguments; 10938 List<DartType> expectedArguments = expectedType.typeArguments;
10875 int length = expectedArguments.length; 10939 int length = expectedArguments.length;
10876 List<DartType> actualArguments = actualType.typeArguments; 10940 List<DartType> actualArguments = actualType.typeArguments;
10877 expect(actualArguments, hasLength(length)); 10941 expect(actualArguments, hasLength(length));
(...skipping 2850 matching lines...) Expand 10 before | Expand all | Expand 10 after
13728 // check propagated type 13792 // check propagated type
13729 FunctionType propagatedType = node.propagatedType as FunctionType; 13793 FunctionType propagatedType = node.propagatedType as FunctionType;
13730 expect(propagatedType.returnType, test.typeProvider.stringType); 13794 expect(propagatedType.returnType, test.typeProvider.stringType);
13731 } on AnalysisException catch (e, stackTrace) { 13795 } on AnalysisException catch (e, stackTrace) {
13732 thrownException[0] = new CaughtException(e, stackTrace); 13796 thrownException[0] = new CaughtException(e, stackTrace);
13733 } 13797 }
13734 } 13798 }
13735 return null; 13799 return null;
13736 } 13800 }
13737 } 13801 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698