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

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

Issue 1683343005: change static method types to not have the class type parameters (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sort Created 4 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/type.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 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/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 10207 matching lines...) Expand 10 before | Expand all | Expand 10 after
10218 """; 10218 """;
10219 _resolveTestUnit(code); 10219 _resolveTestUnit(code);
10220 SimpleIdentifier identifier = _findIdentifier("p()"); 10220 SimpleIdentifier identifier = _findIdentifier("p()");
10221 expect(identifier.staticType, DynamicTypeImpl.instance); 10221 expect(identifier.staticType, DynamicTypeImpl.instance);
10222 { 10222 {
10223 FunctionType type = identifier.propagatedType; 10223 FunctionType type = identifier.propagatedType;
10224 expect(type, isNotNull); 10224 expect(type, isNotNull);
10225 expect(type.name, 'Foo'); 10225 expect(type.name, 'Foo');
10226 } 10226 }
10227 } 10227 }
10228
10229 void test_staticMethods_classTypeParameters() {
10230 String code = r'''
10231 class C<T> {
10232 static void m() => null;
10233 }
10234 main() {
10235 print(C.m);
10236 }
10237 ''';
10238 _resolveTestUnit(code);
10239 SimpleIdentifier identifier = _findIdentifier('m);');
10240 FunctionTypeImpl type = identifier.staticType;
10241 expect(type.toString(), '() → void');
10242 expect(type.typeParameters, isEmpty,
10243 reason: 'static methods should not have type parameters');
10244 expect(type.typeArguments, isEmpty,
10245 reason: 'static methods should not have type arguments');
10246 expect(type.typeFormals, isEmpty,
10247 reason: 'this tatic method is not generic');
vsm 2016/02/11 23:38:27 s/tatic/static/
10248 }
10249
10250 void test_staticMethods_classTypeParameters_genericMethod() {
10251 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
10252 options.enableGenericMethods = true;
10253 resetWithOptions(options);
10254 String code = r'''
10255 class C<T> {
10256 static void m<S>(S s) => null;
10257 }
10258 main() {
10259 print(C.m);
10260 }
10261 ''';
10262 _resolveTestUnit(code);
10263 SimpleIdentifier identifier = _findIdentifier('m);');
10264 FunctionTypeImpl type = identifier.staticType;
10265 expect(type.toString(), '<S>(S) → void');
10266 expect(type.typeParameters, isEmpty,
10267 reason: 'static methods should not have type parameters');
10268 expect(type.typeArguments, isEmpty,
10269 reason: 'static methods should not have type arguments');
10270 expect(type.typeFormals.toString(), '[S]');
10271
10272 type = type.instantiate([DynamicTypeImpl.instance]);
10273 expect(type.toString(), '(dynamic) → void');
10274 expect(type.typeParameters.toString(), '[S]');
10275 expect(type.typeArguments, [DynamicTypeImpl.instance]);
10276 expect(type.typeFormals, isEmpty);
10277 }
10228 } 10278 }
10229 10279
10230 @reflectiveTest 10280 @reflectiveTest
10231 class StaticTypeAnalyzerTest extends EngineTestCase { 10281 class StaticTypeAnalyzerTest extends EngineTestCase {
10232 /** 10282 /**
10233 * The error listener to which errors will be reported. 10283 * The error listener to which errors will be reported.
10234 */ 10284 */
10235 GatheringErrorListener _listener; 10285 GatheringErrorListener _listener;
10236 10286
10237 /** 10287 /**
(...skipping 3143 matching lines...) Expand 10 before | Expand all | Expand 10 after
13381 void test_genericFunction_static() { 13431 void test_genericFunction_static() {
13382 _resolveTestUnit(r''' 13432 _resolveTestUnit(r'''
13383 class C<E> { 13433 class C<E> {
13384 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; 13434 static /*=T*/ f/*<T>*/(/*=T*/ x) => null;
13385 } 13435 }
13386 '''); 13436 ''');
13387 SimpleIdentifier f = _findIdentifier('f'); 13437 SimpleIdentifier f = _findIdentifier('f');
13388 MethodElementImpl e = f.staticElement; 13438 MethodElementImpl e = f.staticElement;
13389 expect(e.typeParameters.toString(), '[T]'); 13439 expect(e.typeParameters.toString(), '[T]');
13390 expect(e.type.typeFormals.toString(), '[T]'); 13440 expect(e.type.typeFormals.toString(), '[T]');
13391 // TODO(jmesserly): we could get rid of this {E/E} substitution, but it's 13441 expect(e.type.typeParameters.toString(), '[]');
13392 // probably harmless, as E won't be used in the function (error verifier 13442 expect(e.type.typeArguments.toString(), '[]');
13393 // checks this), and {E/E} is a no-op anyway.
13394 expect(e.type.typeParameters.toString(), '[E]');
13395 expect(e.type.typeArguments.toString(), '[E]');
13396 expect(e.type.toString(), '<T>(T) → T'); 13443 expect(e.type.toString(), '<T>(T) → T');
13397 13444
13398 FunctionType ft = e.type.instantiate([typeProvider.stringType]); 13445 FunctionType ft = e.type.instantiate([typeProvider.stringType]);
13399 expect(ft.toString(), '(String) → String'); 13446 expect(ft.toString(), '(String) → String');
13400 } 13447 }
13401 13448
13402 void test_genericFunction_typedef() { 13449 void test_genericFunction_typedef() {
13403 String code = r''' 13450 String code = r'''
13404 typedef T F<T>(T x); 13451 typedef T F<T>(T x);
13405 F f0; 13452 F f0;
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
13772 '''; 13819 ''';
13773 _resolveTestUnit(code); 13820 _resolveTestUnit(code);
13774 13821
13775 SimpleIdentifier identifier = _findIdentifier('foo'); 13822 SimpleIdentifier identifier = _findIdentifier('foo');
13776 VariableDeclaration declaration = 13823 VariableDeclaration declaration =
13777 identifier.getAncestor((node) => node is VariableDeclaration); 13824 identifier.getAncestor((node) => node is VariableDeclaration);
13778 expect(declaration.initializer.staticType.name, 'int'); 13825 expect(declaration.initializer.staticType.name, 'int');
13779 expect(declaration.initializer.propagatedType, isNull); 13826 expect(declaration.initializer.propagatedType, isNull);
13780 } 13827 }
13781 13828
13829 void test_genericMethod_nestedBound() {
13830 String code = r'''
13831 class Foo<T extends num> {
13832 void method/*<U extends T>*/(dynamic/*=U*/ u) {
13833 u.abs();
13834 }
13835 }
13836 ''';
13837 // Just validate that there is no warning on the call to `.abs()`.
13838 _resolveTestUnit(code);
13839 }
13840
13782 void test_genericMethod_nestedCapture() { 13841 void test_genericMethod_nestedCapture() {
13783 _resolveTestUnit(r''' 13842 _resolveTestUnit(r'''
13784 class C<T> { 13843 class C<T> {
13785 /*=T*/ f/*<S>*/(/*=S*/ x) { 13844 /*=T*/ f/*<S>*/(/*=S*/ x) {
13786 new C<S>().f/*<int>*/(3); 13845 new C<S>().f/*<int>*/(3);
13787 new C<S>().f; // tear-off 13846 new C<S>().f; // tear-off
13788 return null; 13847 return null;
13789 } 13848 }
13790 } 13849 }
13791 '''); 13850 ''');
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
13995 _resolveTestUnit(code); 14054 _resolveTestUnit(code);
13996 14055
13997 SimpleIdentifier identifier = _findIdentifier('foo'); 14056 SimpleIdentifier identifier = _findIdentifier('foo');
13998 VariableDeclaration declaration = 14057 VariableDeclaration declaration =
13999 identifier.getAncestor((node) => node is VariableDeclaration); 14058 identifier.getAncestor((node) => node is VariableDeclaration);
14000 14059
14001 expect(declaration.initializer.staticType.toString(), "Future<String>"); 14060 expect(declaration.initializer.staticType.toString(), "Future<String>");
14002 expect(declaration.initializer.propagatedType, isNull); 14061 expect(declaration.initializer.propagatedType, isNull);
14003 } 14062 }
14004 14063
14005 void test_genericMethod_nestedBound() {
14006 String code = r'''
14007 class Foo<T extends num> {
14008 void method/*<U extends T>*/(dynamic/*=U*/ u) {
14009 u.abs();
14010 }
14011 }
14012 ''';
14013 // Just validate that there is no warning on the call to `.abs()`.
14014 _resolveTestUnit(code);
14015 }
14016
14017 void test_genericMethod_then_propagatedType() { 14064 void test_genericMethod_then_propagatedType() {
14018 // Regression test for https://github.com/dart-lang/sdk/issues/25482. 14065 // Regression test for https://github.com/dart-lang/sdk/issues/25482.
14019 String code = r''' 14066 String code = r'''
14020 import 'dart:async'; 14067 import 'dart:async';
14021 void main() { 14068 void main() {
14022 Future<String> p; 14069 Future<String> p;
14023 var foo = p.then((r) => new Future<String>.value(3)); 14070 var foo = p.then((r) => new Future<String>.value(3));
14024 } 14071 }
14025 '''; 14072 ''';
14026 // This should produce no hints or warnings. 14073 // This should produce no hints or warnings.
(...skipping 3021 matching lines...) Expand 10 before | Expand all | Expand 10 after
17048 17095
17049 void _resolveTestUnit(String code) { 17096 void _resolveTestUnit(String code) {
17050 testCode = code; 17097 testCode = code;
17051 testSource = addSource(testCode); 17098 testSource = addSource(testCode);
17052 LibraryElement library = resolve2(testSource); 17099 LibraryElement library = resolve2(testSource);
17053 assertNoErrors(testSource); 17100 assertNoErrors(testSource);
17054 verify([testSource]); 17101 verify([testSource]);
17055 testUnit = resolveCompilationUnit(testSource, library); 17102 testUnit = resolveCompilationUnit(testSource, library);
17056 } 17103 }
17057 } 17104 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/type.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698