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

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

Issue 895113002: Add static type checking of "yield" statements to analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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';
11 import 'package:analyzer/src/generated/element_resolver.dart'; 11 import 'package:analyzer/src/generated/element_resolver.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/java_core.dart'; 14 import 'package:analyzer/src/generated/java_core.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 15 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/java_engine_io.dart'; 16 import 'package:analyzer/src/generated/java_engine_io.dart';
17 import 'package:analyzer/src/generated/java_io.dart'; 17 import 'package:analyzer/src/generated/java_io.dart';
18 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 18 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
19 import 'package:analyzer/src/generated/resolver.dart'; 19 import 'package:analyzer/src/generated/resolver.dart';
20 import 'package:analyzer/src/generated/scanner.dart'; 20 import 'package:analyzer/src/generated/scanner.dart';
21 import 'package:analyzer/src/generated/sdk.dart'; 21 import 'package:analyzer/src/generated/sdk.dart';
22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
23 import 'package:analyzer/src/generated/source_io.dart'; 23 import 'package:analyzer/src/generated/source_io.dart';
24 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 24 import 'package:analyzer/src/generated/static_type_analyzer.dart';
25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 25 import 'package:analyzer/src/generated/testing/ast_factory.dart';
26 import 'package:analyzer/src/generated/testing/element_factory.dart'; 26 import 'package:analyzer/src/generated/testing/element_factory.dart';
27 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; 27 import 'package:analyzer/src/generated/testing/test_type_provider.dart';
28 import 'package:analyzer/src/generated/testing/token_factory.dart';
28 import 'package:analyzer/src/generated/utilities_dart.dart'; 29 import 'package:analyzer/src/generated/utilities_dart.dart';
29 import 'package:unittest/unittest.dart'; 30 import 'package:unittest/unittest.dart';
30 31
31 import '../reflective_tests.dart'; 32 import '../reflective_tests.dart';
32 import 'test_support.dart'; 33 import 'test_support.dart';
33 34
34 35
35 main() { 36 main() {
36 groupSep = ' | '; 37 groupSep = ' | ';
37 runReflectiveTests(AnalysisDeltaTest); 38 runReflectiveTests(AnalysisDeltaTest);
(...skipping 9960 matching lines...) Expand 10 before | Expand all | Expand 10 after
9998 _listener.assertNoErrors(); 9999 _listener.assertNoErrors();
9999 } 10000 }
10000 10001
10001 void test_visitDoubleLiteral() { 10002 void test_visitDoubleLiteral() {
10002 // 4.33 10003 // 4.33
10003 Expression node = AstFactory.doubleLiteral(4.33); 10004 Expression node = AstFactory.doubleLiteral(4.33);
10004 expect(_analyze(node), same(_typeProvider.doubleType)); 10005 expect(_analyze(node), same(_typeProvider.doubleType));
10005 _listener.assertNoErrors(); 10006 _listener.assertNoErrors();
10006 } 10007 }
10007 10008
10009 void test_visitFunctionExpression_generator_async() {
10010 // () async* {}
10011 BlockFunctionBody body = AstFactory.blockFunctionBody2();
10012 body.keyword = TokenFactory.tokenFromString('async');
10013 body.star = TokenFactory.tokenFromType(TokenType.STAR);
10014 FunctionExpression node =
10015 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10016 DartType resultType = _analyze(node);
10017 _assertFunctionType(
10018 _typeProvider.streamDynamicType,
10019 null,
10020 null,
10021 null,
10022 resultType);
10023 _listener.assertNoErrors();
10024 }
10025
10026 void test_visitFunctionExpression_generator_sync() {
10027 // () sync* {}
10028 BlockFunctionBody body = AstFactory.blockFunctionBody2();
10029 body.keyword = TokenFactory.tokenFromString('sync');
10030 body.star = TokenFactory.tokenFromType(TokenType.STAR);
10031 FunctionExpression node =
10032 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body);
10033 DartType resultType = _analyze(node);
10034 _assertFunctionType(
10035 _typeProvider.iterableDynamicType,
10036 null,
10037 null,
10038 null,
10039 resultType);
10040 _listener.assertNoErrors();
10041 }
10042
10008 void test_visitFunctionExpression_named_block() { 10043 void test_visitFunctionExpression_named_block() {
10009 // ({p1 : 0, p2 : 0}) {} 10044 // ({p1 : 0, p2 : 0}) {}
10010 DartType dynamicType = _typeProvider.dynamicType; 10045 DartType dynamicType = _typeProvider.dynamicType;
10011 FormalParameter p1 = AstFactory.namedFormalParameter( 10046 FormalParameter p1 = AstFactory.namedFormalParameter(
10012 AstFactory.simpleFormalParameter3("p1"), 10047 AstFactory.simpleFormalParameter3("p1"),
10013 _resolvedInteger(0)); 10048 _resolvedInteger(0));
10014 _setType(p1, dynamicType); 10049 _setType(p1, dynamicType);
10015 FormalParameter p2 = AstFactory.namedFormalParameter( 10050 FormalParameter p2 = AstFactory.namedFormalParameter(
10016 AstFactory.simpleFormalParameter3("p2"), 10051 AstFactory.simpleFormalParameter3("p2"),
10017 _resolvedInteger(0)); 10052 _resolvedInteger(0));
(...skipping 2967 matching lines...) Expand 10 before | Expand all | Expand 10 after
12985 // ElementFactory) because we side-effect the elements in ways that would 13020 // ElementFactory) because we side-effect the elements in ways that would
12986 // break other tests. 13021 // break other tests.
12987 // 13022 //
12988 InterfaceType objectType = _classElement("Object", null).type; 13023 InterfaceType objectType = _classElement("Object", null).type;
12989 InterfaceType boolType = _classElement("bool", objectType).type; 13024 InterfaceType boolType = _classElement("bool", objectType).type;
12990 InterfaceType numType = _classElement("num", objectType).type; 13025 InterfaceType numType = _classElement("num", objectType).type;
12991 InterfaceType doubleType = _classElement("double", numType).type; 13026 InterfaceType doubleType = _classElement("double", numType).type;
12992 InterfaceType functionType = _classElement("Function", objectType).type; 13027 InterfaceType functionType = _classElement("Function", objectType).type;
12993 InterfaceType futureType = _classElement("Future", objectType, ["T"]).type; 13028 InterfaceType futureType = _classElement("Future", objectType, ["T"]).type;
12994 InterfaceType intType = _classElement("int", numType).type; 13029 InterfaceType intType = _classElement("int", numType).type;
13030 InterfaceType iterableType =
13031 _classElement("Iterable", objectType, ["T"]).type;
12995 InterfaceType listType = _classElement("List", objectType, ["E"]).type; 13032 InterfaceType listType = _classElement("List", objectType, ["E"]).type;
12996 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; 13033 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type;
12997 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; 13034 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type;
13035 InterfaceType streamType = _classElement("Stream", objectType, ["T"]).type;
12998 InterfaceType stringType = _classElement("String", objectType).type; 13036 InterfaceType stringType = _classElement("String", objectType).type;
12999 InterfaceType symbolType = _classElement("Symbol", objectType).type; 13037 InterfaceType symbolType = _classElement("Symbol", objectType).type;
13000 InterfaceType typeType = _classElement("Type", objectType).type; 13038 InterfaceType typeType = _classElement("Type", objectType).type;
13001 CompilationUnitElementImpl coreUnit = 13039 CompilationUnitElementImpl coreUnit =
13002 new CompilationUnitElementImpl("core.dart"); 13040 new CompilationUnitElementImpl("core.dart");
13003 coreUnit.types = <ClassElement>[ 13041 coreUnit.types = <ClassElement>[
13004 boolType.element, 13042 boolType.element,
13005 doubleType.element, 13043 doubleType.element,
13006 functionType.element, 13044 functionType.element,
13007 intType.element, 13045 intType.element,
13046 iterableType.element,
13008 listType.element, 13047 listType.element,
13009 mapType.element, 13048 mapType.element,
13010 objectType.element, 13049 objectType.element,
13011 stackTraceType.element, 13050 stackTraceType.element,
13012 stringType.element, 13051 stringType.element,
13013 symbolType.element, 13052 symbolType.element,
13014 typeType.element]; 13053 typeType.element];
13015 CompilationUnitElementImpl asyncUnit = 13054 CompilationUnitElementImpl asyncUnit =
13016 new CompilationUnitElementImpl("async.dart"); 13055 new CompilationUnitElementImpl("async.dart");
13017 asyncUnit.types = <ClassElement>[futureType.element]; 13056 asyncUnit.types = <ClassElement>[futureType.element, streamType.element];
13018 AnalysisContextImpl context = new AnalysisContextImpl(); 13057 AnalysisContextImpl context = new AnalysisContextImpl();
13019 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( 13058 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(
13020 context, 13059 context,
13021 AstFactory.libraryIdentifier2(["dart.core"])); 13060 AstFactory.libraryIdentifier2(["dart.core"]));
13022 coreLibrary.definingCompilationUnit = coreUnit; 13061 coreLibrary.definingCompilationUnit = coreUnit;
13023 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( 13062 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(
13024 context, 13063 context,
13025 AstFactory.libraryIdentifier2(["dart.async"])); 13064 AstFactory.libraryIdentifier2(["dart.async"]));
13026 asyncLibrary.definingCompilationUnit = asyncUnit; 13065 asyncLibrary.definingCompilationUnit = asyncUnit;
13027 // 13066 //
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
13665 // check propagated type 13704 // check propagated type
13666 FunctionType propagatedType = node.propagatedType as FunctionType; 13705 FunctionType propagatedType = node.propagatedType as FunctionType;
13667 expect(propagatedType.returnType, test.typeProvider.stringType); 13706 expect(propagatedType.returnType, test.typeProvider.stringType);
13668 } on AnalysisException catch (e, stackTrace) { 13707 } on AnalysisException catch (e, stackTrace) {
13669 thrownException[0] = new CaughtException(e, stackTrace); 13708 thrownException[0] = new CaughtException(e, stackTrace);
13670 } 13709 }
13671 } 13710 }
13672 return null; 13711 return null;
13673 } 13712 }
13674 } 13713 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698