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

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

Issue 1506903005: Issue 24648. Report HintCode.UNNECESSARY_NO_SUCH_METHOD. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/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/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 3571 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 void test_unnecessaryCast_type_type() { 3582 void test_unnecessaryCast_type_type() {
3583 Source source = addSource(r''' 3583 Source source = addSource(r'''
3584 m(num i) { 3584 m(num i) {
3585 var b = i as num; 3585 var b = i as num;
3586 }'''); 3586 }''');
3587 computeLibrarySourceErrors(source); 3587 computeLibrarySourceErrors(source);
3588 assertErrors(source, [HintCode.UNNECESSARY_CAST]); 3588 assertErrors(source, [HintCode.UNNECESSARY_CAST]);
3589 verify([source]); 3589 verify([source]);
3590 } 3590 }
3591 3591
3592 void test_unnecessaryNoSuchMethod_blockBody() {
3593 Source source = addSource(r'''
3594 class A {
3595 noSuchMethod(x) => super.noSuchMethod(x);
3596 }
3597 class B extends A {
3598 mmm();
3599 noSuchMethod(y) {
3600 return super.noSuchMethod(y);
3601 }
3602 }''');
3603 computeLibrarySourceErrors(source);
3604 assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]);
3605 verify([source]);
3606 }
3607
3608 void test_unnecessaryNoSuchMethod_expressionBody() {
3609 Source source = addSource(r'''
3610 class A {
3611 noSuchMethod(x) => super.noSuchMethod(x);
3612 }
3613 class B extends A {
3614 mmm();
3615 noSuchMethod(y) => super.noSuchMethod(y);
3616 }''');
3617 computeLibrarySourceErrors(source);
3618 assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]);
3619 verify([source]);
3620 }
3621
3592 void test_unnecessaryTypeCheck_null_is_Null() { 3622 void test_unnecessaryTypeCheck_null_is_Null() {
3593 Source source = addSource("bool b = null is Null;"); 3623 Source source = addSource("bool b = null is Null;");
3594 computeLibrarySourceErrors(source); 3624 computeLibrarySourceErrors(source);
3595 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); 3625 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]);
3596 verify([source]); 3626 verify([source]);
3597 } 3627 }
3598 3628
3599 void test_unnecessaryTypeCheck_null_not_Null() { 3629 void test_unnecessaryTypeCheck_null_not_Null() {
3600 Source source = addSource("bool b = null is! Null;"); 3630 Source source = addSource("bool b = null is! Null;");
3601 computeLibrarySourceErrors(source); 3631 computeLibrarySourceErrors(source);
(...skipping 3972 matching lines...) Expand 10 before | Expand all | Expand 10 after
7574 void test_unnecessaryCast_type_dynamic() { 7604 void test_unnecessaryCast_type_dynamic() {
7575 Source source = addSource(r''' 7605 Source source = addSource(r'''
7576 m(v) { 7606 m(v) {
7577 var b = Object as dynamic; 7607 var b = Object as dynamic;
7578 }'''); 7608 }''');
7579 computeLibrarySourceErrors(source); 7609 computeLibrarySourceErrors(source);
7580 assertNoErrors(source); 7610 assertNoErrors(source);
7581 verify([source]); 7611 verify([source]);
7582 } 7612 }
7583 7613
7614 void test_unnecessaryNoSuchMethod_blockBody_notReturnStatement() {
7615 Source source = addSource(r'''
7616 class A {
7617 noSuchMethod(x) => super.noSuchMethod(x);
7618 }
7619 class B extends A {
7620 mmm();
7621 noSuchMethod(y) {
7622 print(y);
7623 }
7624 }''');
7625 computeLibrarySourceErrors(source);
7626 assertNoErrors(source);
7627 verify([source]);
7628 }
7629
7630 void test_unnecessaryNoSuchMethod_blockBody_notSingleStatement() {
7631 Source source = addSource(r'''
7632 class A {
7633 noSuchMethod(x) => super.noSuchMethod(x);
7634 }
7635 class B extends A {
7636 mmm();
7637 noSuchMethod(y) {
7638 print(y);
7639 return super.noSuchMethod(y);
7640 }
7641 }''');
7642 computeLibrarySourceErrors(source);
7643 assertNoErrors(source);
7644 verify([source]);
7645 }
7646
7647 void test_unnecessaryNoSuchMethod_expressionBody_notNoSuchMethod() {
7648 Source source = addSource(r'''
7649 class A {
7650 noSuchMethod(x) => super.noSuchMethod(x);
7651 }
7652 class B extends A {
7653 mmm();
7654 noSuchMethod(y) => super.hashCode;
7655 }''');
7656 computeLibrarySourceErrors(source);
7657 assertNoErrors(source);
7658 verify([source]);
7659 }
7660
7661 void test_unnecessaryNoSuchMethod_expressionBody_notSuper() {
7662 Source source = addSource(r'''
7663 class A {
7664 noSuchMethod(x) => super.noSuchMethod(x);
7665 }
7666 class B extends A {
7667 mmm();
7668 noSuchMethod(y) => 42;
7669 }''');
7670 computeLibrarySourceErrors(source);
7671 assertNoErrors(source);
7672 verify([source]);
7673 }
7674
7584 void test_unusedImport_annotationOnDirective() { 7675 void test_unusedImport_annotationOnDirective() {
7585 Source source = addSource(r''' 7676 Source source = addSource(r'''
7586 library L; 7677 library L;
7587 @A() 7678 @A()
7588 import 'lib1.dart';'''); 7679 import 'lib1.dart';''');
7589 Source source2 = addNamedSource( 7680 Source source2 = addNamedSource(
7590 "/lib1.dart", 7681 "/lib1.dart",
7591 r''' 7682 r'''
7592 library lib1; 7683 library lib1;
7593 class A { 7684 class A {
(...skipping 5551 matching lines...) Expand 10 before | Expand all | Expand 10 after
13145 '''; 13236 ''';
13146 _resolveTestUnit(code); 13237 _resolveTestUnit(code);
13147 13238
13148 SimpleIdentifier identifier = _findIdentifier('foo'); 13239 SimpleIdentifier identifier = _findIdentifier('foo');
13149 VariableDeclaration declaration = 13240 VariableDeclaration declaration =
13150 identifier.getAncestor((node) => node is VariableDeclaration); 13241 identifier.getAncestor((node) => node is VariableDeclaration);
13151 expect(declaration.initializer.staticType.name, 'String'); 13242 expect(declaration.initializer.staticType.name, 'String');
13152 expect(declaration.initializer.propagatedType, isNull); 13243 expect(declaration.initializer.propagatedType, isNull);
13153 } 13244 }
13154 13245
13246 void test_genericFunction() {
13247 if (!AnalysisEngine.instance.useTaskModel) {
13248 return;
13249 }
13250 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;');
13251 SimpleIdentifier f = _findIdentifier('f');
13252 FunctionElementImpl e = f.staticElement;
13253 expect(e.typeParameters.toString(), '[T]');
13254 expect(e.type.boundTypeParameters.toString(), '[T]');
13255 expect(e.type.typeParameters.toString(), '[]');
13256 expect(e.type.toString(), '<T>(T) → T');
13257
13258 FunctionType ft = e.type.instantiate([typeProvider.stringType]);
13259 expect(ft.toString(), '(String) → String');
13260 }
13261
13155 void test_genericFunction_typedef() { 13262 void test_genericFunction_typedef() {
13156 String code = r''' 13263 String code = r'''
13157 typedef T F<T>(T x); 13264 typedef T F<T>(T x);
13158 F f0; 13265 F f0;
13159 13266
13160 class C { 13267 class C {
13161 static F f1; 13268 static F f1;
13162 F f2; 13269 F f2;
13163 void g(F f3) { 13270 void g(F f3) {
13164 F f4; 13271 F f4;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
13220 Expression exp3 = exps3.expression; 13327 Expression exp3 = exps3.expression;
13221 Expression exp4 = exps4.expression; 13328 Expression exp4 = exps4.expression;
13222 expect(exp0.staticType, typeProvider.dynamicType); 13329 expect(exp0.staticType, typeProvider.dynamicType);
13223 expect(exp1.staticType, typeProvider.dynamicType); 13330 expect(exp1.staticType, typeProvider.dynamicType);
13224 expect(exp2.staticType, typeProvider.dynamicType); 13331 expect(exp2.staticType, typeProvider.dynamicType);
13225 expect(exp3.staticType, typeProvider.dynamicType); 13332 expect(exp3.staticType, typeProvider.dynamicType);
13226 expect(exp4.staticType, typeProvider.dynamicType); 13333 expect(exp4.staticType, typeProvider.dynamicType);
13227 } 13334 }
13228 } 13335 }
13229 13336
13230 void test_genericFunction() {
13231 if (!AnalysisEngine.instance.useTaskModel) {
13232 return;
13233 }
13234 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;');
13235 SimpleIdentifier f = _findIdentifier('f');
13236 FunctionElementImpl e = f.staticElement;
13237 expect(e.typeParameters.toString(), '[T]');
13238 expect(e.type.boundTypeParameters.toString(), '[T]');
13239 expect(e.type.typeParameters.toString(), '[]');
13240 expect(e.type.toString(), '<T>(T) → T');
13241
13242 FunctionType ft = e.type.instantiate([typeProvider.stringType]);
13243 expect(ft.toString(), '(String) → String');
13244 }
13245
13246 void test_genericMethod() { 13337 void test_genericMethod() {
13247 if (!AnalysisEngine.instance.useTaskModel) { 13338 if (!AnalysisEngine.instance.useTaskModel) {
13248 return; 13339 return;
13249 } 13340 }
13250 _resolveTestUnit(r''' 13341 _resolveTestUnit(r'''
13251 class C<E> { 13342 class C<E> {
13252 List/*<T>*/ f/*<T>*/(E e) => null; 13343 List/*<T>*/ f/*<T>*/(E e) => null;
13253 } 13344 }
13254 main() { 13345 main() {
13255 C<String> cOfString; 13346 C<String> cOfString;
(...skipping 3138 matching lines...) Expand 10 before | Expand all | Expand 10 after
16394 16485
16395 void _resolveTestUnit(String code) { 16486 void _resolveTestUnit(String code) {
16396 testCode = code; 16487 testCode = code;
16397 testSource = addSource(testCode); 16488 testSource = addSource(testCode);
16398 LibraryElement library = resolve2(testSource); 16489 LibraryElement library = resolve2(testSource);
16399 assertNoErrors(testSource); 16490 assertNoErrors(testSource);
16400 verify([testSource]); 16491 verify([testSource]);
16401 testUnit = resolveCompilationUnit(testSource, library); 16492 testUnit = resolveCompilationUnit(testSource, library);
16402 } 16493 }
16403 } 16494 }
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