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

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

Issue 1568653002: Add some generic method tests (currently failing) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | 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 analyzer.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 11806 matching lines...) Expand 10 before | Expand all | Expand 10 after
11817 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType> 11817 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType>
11818 _isMapOf; 11818 _isMapOf;
11819 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf; 11819 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf;
11820 AsserterBuilder<DartType, DartType> _isType; 11820 AsserterBuilder<DartType, DartType> _isType;
11821 11821
11822 AsserterBuilder<Element, DartType> _hasElement; 11822 AsserterBuilder<Element, DartType> _hasElement;
11823 AsserterBuilder<DartType, DartType> _sameElement; 11823 AsserterBuilder<DartType, DartType> _sameElement;
11824 11824
11825 @override 11825 @override
11826 void setUp() { 11826 void setUp() {
11827 super.setUp();
11827 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 11828 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
11828 options.strongMode = true; 11829 options.strongMode = true;
11829 resetWithOptions(options); 11830 resetWithOptions(options);
11830 _assertions = new TypeAssertions(typeProvider); 11831 _assertions = new TypeAssertions(typeProvider);
11831 _isType = _assertions.isType; 11832 _isType = _assertions.isType;
11832 _hasElement = _assertions.hasElement; 11833 _hasElement = _assertions.hasElement;
11833 _isInstantiationOf = _assertions.isInstantiationOf; 11834 _isInstantiationOf = _assertions.isInstantiationOf;
11834 _isInt = _assertions.isInt; 11835 _isInt = _assertions.isInt;
11835 _isNum = _assertions.isNum; 11836 _isNum = _assertions.isNum;
11836 _isString = _assertions.isString; 11837 _isString = _assertions.isString;
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
13013 check("f2", _isListOf(_isInt)); 13014 check("f2", _isListOf(_isInt));
13014 check("f3", _isListOf(_isListOf(_isInt))); 13015 check("f3", _isListOf(_isListOf(_isInt)));
13015 } 13016 }
13016 } 13017 }
13017 13018
13018 /** 13019 /**
13019 * Strong mode static analyzer end to end tests 13020 * Strong mode static analyzer end to end tests
13020 */ 13021 */
13021 @reflectiveTest 13022 @reflectiveTest
13022 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { 13023 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared {
13024 void fail_genericFunction_parameter() {
13025 _resolveTestUnit(r'''
13026 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {}
13027 ''');
13028 SimpleIdentifier f = _findIdentifier('f');
13029 ParameterElementImpl e = f.staticElement;
13030 expect(e.typeParameters.toString(), '[T]');
13031 expect(e.type.boundTypeParameters.toString(), '[T]');
13032 expect(e.type.toString(), '<T>(T) → T');
13033 FunctionType ft = e.type.instantiate([typeProvider.stringType]);
13034 expect(ft.toString(), '(String) → String');
13035 }
13036
13037 void fail_genericMethod_functionExpressionInvocation_explicit() {
13038 _resolveTestUnit(r'''
13039 class C<E> {
13040 /*=T*/ f/*<T>*/(/*=T*/ e) => null;
13041 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13042 static final h = g;
13043 }
13044
13045 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13046 var topG = topF;
13047 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13048 var c = new C<int>();
13049 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13050 var methodCall = (c.f)/*<int>*/(3);
13051 var staticCall = (C.g)/*<int>*/(3);
13052 var staticFieldCall = (C.h)/*<int>*/(3);
13053 var topFunCall = (topF)/*<int>*/(3);
13054 var topFieldCall = (topG)/*<int>*/(3);
13055 var localCall = (lf)/*<int>*/(3);
13056 var paramCall = (pf)/*<int>*/(3);
13057 }
13058 ''');
13059 expect(_findIdentifier('methodCall').staticType.toString(), "int");
13060 expect(_findIdentifier('staticCall').staticType.toString(), "int");
13061 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
13062 expect(_findIdentifier('topFunCall').staticType.toString(), "int");
13063 expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
13064 expect(_findIdentifier('localCall').staticType.toString(), "int");
13065 expect(_findIdentifier('paramCall').staticType.toString(), "int");
13066 }
13067
13068 void fail_genericMethod_functionExpressionInvocation_inferred() {
13069 _resolveTestUnit(r'''
13070 class C<E> {
13071 /*=T*/ f/*<T>*/(/*=T*/ e) => null;
13072 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13073 static final h = g;
13074 }
13075
13076 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13077 var topG = topF;
13078 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13079 var c = new C<int>();
13080 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13081 var methodCall = (c.f)(3);
13082 var staticCall = (C.g)(3);
13083 var staticFieldCall = (C.h)(3);
13084 var topFunCall = (topF)(3);
13085 var topFieldCall = (topG)(3);
13086 var localCall = (lf)(3);
13087 var paramCall = (pf)(3);
13088 }
13089 ''');
13090 expect(_findIdentifier('methodCall').staticType.toString(), "int");
13091 expect(_findIdentifier('staticCall').staticType.toString(), "int");
13092 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
13093 expect(_findIdentifier('topFunCall').staticType.toString(), "int");
13094 expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
13095 expect(_findIdentifier('localCall').staticType.toString(), "int");
13096 expect(_findIdentifier('paramCall').staticType.toString(), "int");
13097 }
13098
13099 void fail_genericMethod_functionInvocation_explicit() {
13100 _resolveTestUnit(r'''
13101 class C<E> {
13102 /*=T*/ f/*<T>*/(/*=T*/ e) => null;
13103 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13104 static final h = g;
13105 }
13106
13107 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13108 var topG = topF;
13109 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13110 var c = new C<int>();
13111 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13112 var methodCall = c.f/*<int>*/(3);
13113 var staticCall = C.g/*<int>*/(3);
13114 var staticFieldCall = C.h/*<int>*/(3);
13115 var topFunCall = topF/*<int>*/(3);
13116 var topFieldCall = topG/*<int>*/(3);
13117 var localCall = lf/*<int>*/(3);
13118 var paramCall = pf/*<int>*/(3);
13119 }
13120 ''');
13121 expect(_findIdentifier('methodCall').staticType.toString(), "int");
13122 expect(_findIdentifier('staticCall').staticType.toString(), "int");
13123 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
13124 expect(_findIdentifier('topFunCall').staticType.toString(), "int");
13125 expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
13126 expect(_findIdentifier('localCall').staticType.toString(), "int");
13127 expect(_findIdentifier('paramCall').staticType.toString(), "int");
13128 }
13129
13130 void fail_genericMethod_functionInvocation_inferred() {
13131 _resolveTestUnit(r'''
13132 class C<E> {
13133 /*=T*/ f/*<T>*/(/*=T*/ e) => null;
13134 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13135 static final h = g;
13136 }
13137
13138 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13139 var topG = topF;
13140 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13141 var c = new C<int>();
13142 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13143 var methodCall = c.f(3);
13144 var staticCall = C.g(3);
13145 var staticFieldCall = C.h(3);
13146 var topFunCall = topF(3);
13147 var topFieldCall = topG(3);
13148 var localCall = lf(3);
13149 var paramCall = pf(3);
13150 }
13151 ''');
13152 expect(_findIdentifier('methodCall').staticType.toString(), "int");
13153 expect(_findIdentifier('staticCall').staticType.toString(), "int");
13154 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
13155 expect(_findIdentifier('topFunCall').staticType.toString(), "int");
13156 expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
13157 expect(_findIdentifier('localCall').staticType.toString(), "int");
13158 expect(_findIdentifier('paramCall').staticType.toString(), "int");
13159 }
13160
13161 void fail_genericMethod_tearoff() {
13162 _resolveTestUnit(r'''
13163 class C<E> {
13164 /*=T*/ f/*<T>*/(E e) => null;
13165 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13166 static final h = g;
13167 }
13168
13169 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13170 var topG = topF;
13171 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13172 var c = new C<int>();
13173 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13174 var methodTearOff = c.f;
13175 var staticTearOff = C.g;
13176 var staticFieldTearOff = C.h;
13177 var topFunTearOff = topF;
13178 var topFieldTearOff = topG;
13179 var localTearOff = lf;
13180 var paramTearOff = pf;
13181 }
13182 ''');
13183 expect(
13184 _findIdentifier('methodTearOff').staticType.toString(), "<T>(int) → T");
13185 expect(
13186 _findIdentifier('staticTearOff').staticType.toString(), "<T>(T) → T");
13187 expect(_findIdentifier('staticFieldTearOff').staticType.toString(),
13188 "<T>(T) → T");
13189 expect(
13190 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T");
13191 expect(
13192 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T");
13193 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T");
13194 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T");
13195 }
13196
13197 void fail_genericMethod_tearoff_instantiated() {
13198 _resolveTestUnit(r'''
13199 class C<E> {
13200 /*=T*/ f/*<T>*/(E e) => null;
13201 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
13202 static final h = g;
13203 }
13204
13205 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
13206 var topG = topF;
13207 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
13208 var c = new C<int>();
13209 /*=T*/ lf/*<T>*/(/*=T*/ e) => null;
13210 var methodTearOffInst = c.f/*<int>*/;
13211 var staticTearOffInst = C.g/*<int>*/;
13212 var staticFieldTearOffInst = C.h/*<int>*/;
13213 var topFunTearOffInst = topF/*<int>*/;
13214 var topFieldTearOffInst = topG/*<int>*/;
13215 var localTearOffInst = lf/*<int>*/;
13216 var paramTearOffInst = pf/*<int>*/;
13217 }
13218 ''');
13219 expect(_findIdentifier('methodTearOffInst').staticType.toString(),
13220 "(int) → int");
13221 expect(_findIdentifier('staticTearOffInst').staticType.toString(),
13222 "(int) → int");
13223 expect(_findIdentifier('staticFieldTearOffInst').staticType.toString(),
13224 "(int) → int");
13225 expect(_findIdentifier('topFunTearOffInst').staticType.toString(),
13226 "(int) → int");
13227 expect(_findIdentifier('topFieldTearOffInst').staticType.toString(),
13228 "(int) → int");
13229 expect(_findIdentifier('localTearOffInst').staticType.toString(),
13230 "(int) → int");
13231 expect(_findIdentifier('paramTearOffInst').staticType.toString(),
13232 "(int) → int");
13233 }
13234
13023 void setUp() { 13235 void setUp() {
13236 super.setUp();
13024 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 13237 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
13025 options.strongMode = true; 13238 options.strongMode = true;
13026 resetWithOptions(options); 13239 resetWithOptions(options);
13027 } 13240 }
13028 13241
13029 void test_dynamicObjectGetter_hashCode() { 13242 void test_dynamicObjectGetter_hashCode() {
13030 String code = r''' 13243 String code = r'''
13031 main() { 13244 main() {
13032 dynamic a = null; 13245 dynamic a = null;
13033 var foo = a.hashCode; 13246 var foo = a.hashCode;
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
13538 identifier.getAncestor((node) => node is VariableDeclaration); 13751 identifier.getAncestor((node) => node is VariableDeclaration);
13539 expect(declaration.initializer.staticType.name, 'int'); 13752 expect(declaration.initializer.staticType.name, 'int');
13540 expect(declaration.initializer.propagatedType, isNull); 13753 expect(declaration.initializer.propagatedType, isNull);
13541 } 13754 }
13542 } 13755 }
13543 13756
13544 @reflectiveTest 13757 @reflectiveTest
13545 class StrongModeTypePropagationTest extends ResolverTestCase { 13758 class StrongModeTypePropagationTest extends ResolverTestCase {
13546 @override 13759 @override
13547 void setUp() { 13760 void setUp() {
13761 super.setUp();
13548 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 13762 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
13549 options.strongMode = true; 13763 options.strongMode = true;
13550 resetWithOptions(options); 13764 resetWithOptions(options);
13551 } 13765 }
13552 13766
13553 void test_foreachInference_dynamic_disabled() { 13767 void test_foreachInference_dynamic_disabled() {
13554 String code = r''' 13768 String code = r'''
13555 main() { 13769 main() {
13556 var list = <int>[]; 13770 var list = <int>[];
13557 for (dynamic v in list) { 13771 for (dynamic v in list) {
(...skipping 2821 matching lines...) Expand 10 before | Expand all | Expand 10 after
16379 16593
16380 void _resolveTestUnit(String code) { 16594 void _resolveTestUnit(String code) {
16381 testCode = code; 16595 testCode = code;
16382 testSource = addSource(testCode); 16596 testSource = addSource(testCode);
16383 LibraryElement library = resolve2(testSource); 16597 LibraryElement library = resolve2(testSource);
16384 assertNoErrors(testSource); 16598 assertNoErrors(testSource);
16385 verify([testSource]); 16599 verify([testSource]);
16386 testUnit = resolveCompilationUnit(testSource, library); 16600 testUnit = resolveCompilationUnit(testSource, library);
16387 } 16601 }
16388 } 16602 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698