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

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

Issue 1514683002: fix #25183, add support to ErrorVerifier for generic methods (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
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'; 9 import 'package:analyzer/src/context/context.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 12954 matching lines...) Expand 10 before | Expand all | Expand 10 after
12965 g/*<S>*/(/*=S*/ x) => f; 12965 g/*<S>*/(/*=S*/ x) => f;
12966 return null; 12966 return null;
12967 } 12967 }
12968 '''); 12968 ''');
12969 SimpleIdentifier g = _findIdentifier('f'); 12969 SimpleIdentifier g = _findIdentifier('f');
12970 expect(g.staticType.toString(), '<S>(S) → S'); 12970 expect(g.staticType.toString(), '<S>(S) → S');
12971 SimpleIdentifier f = _findIdentifier('g'); 12971 SimpleIdentifier f = _findIdentifier('g');
12972 expect(f.staticType.toString(), '<S>(S) → dynamic'); 12972 expect(f.staticType.toString(), '<S>(S) → dynamic');
12973 } 12973 }
12974 12974
12975 void test_genericMethod_override() {
12976 _resolveTestUnit(r'''
12977 class C {
12978 /*=T*/ f/*<T>*/(/*=T*/ x) => null;
12979 }
12980 class D extends C {
12981 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D
12982 }
12983 ''');
12984 SimpleIdentifier f =
12985 _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D');
12986 MethodElementImpl e = f.staticElement;
12987 expect(e.typeParameters.toString(), '[T]');
12988 expect(e.type.boundTypeParameters.toString(), '[T]');
12989 expect(e.type.toString(), '<T>(T) → T');
12990
12991 FunctionType ft = e.type.instantiate([typeProvider.stringType]);
12992 expect(ft.toString(), '(String) → String');
12993 }
12994
12995 void test_genericMethod_override_bounds() {
12996 _resolveTestUnit(r'''
12997 class A {}
12998 class B extends A {}
12999 class C {
13000 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null;
13001 }
13002 class D extends C {
13003 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null;
13004 }
13005 ''');
13006 }
13007
13008 void test_genericMethod_override_invalidIypeParamBounds() {
Leaf 2015/12/09 22:02:29 InvalidIype -> InvalidType
Jennifer Messerly 2015/12/09 22:37:41 Done.
13009 Source source = addSource(r'''
13010 class A {}
13011 class B extends A {}
13012 class C {
13013 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null;
13014 }
13015 class D extends C {
13016 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null;
13017 }''');
13018 // TODO(jmesserly): this is modified code from assertErrors, which we can't
13019 // use directly because STRONG_MODE_* errors don't have working equality.
13020 List<AnalysisError> errors = analysisContext2.computeErrors(source);
13021 expect(errors.map((e) => e.errorCode.name), [
13022 'STRONG_MODE_INVALID_METHOD_OVERRIDE',
13023 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND'
13024 ]);
13025 verify([source]);
13026 }
13027
13028 void test_genericMethod_override_invalidTypeParamCount() {
13029 Source source = addSource(r'''
13030 class C {
13031 /*=T*/ f/*<T>*/(/*=T*/ x) => null;
13032 }
13033 class D extends C {
13034 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null;
13035 }''');
13036 // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors
13037 // from CodeChecker don't have working equality.
13038 List<AnalysisError> errors = analysisContext2.computeErrors(source);
13039 expect(errors.map((e) => e.errorCode.name), [
13040 'STRONG_MODE_INVALID_METHOD_OVERRIDE',
13041 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS'
13042 ]);
13043 verify([source]);
13044 }
13045
12975 void test_pseudoGeneric_max_doubleDouble() { 13046 void test_pseudoGeneric_max_doubleDouble() {
12976 String code = r''' 13047 String code = r'''
12977 import 'dart:math'; 13048 import 'dart:math';
12978 main() { 13049 main() {
12979 var foo = max(1.0, 2.0); 13050 var foo = max(1.0, 2.0);
12980 } 13051 }
12981 '''; 13052 ''';
12982 _resolveTestUnit(code); 13053 _resolveTestUnit(code);
12983 13054
12984 SimpleIdentifier identifier = _findIdentifier('foo'); 13055 SimpleIdentifier identifier = _findIdentifier('foo');
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after
15957 16028
15958 void _resolveTestUnit(String code) { 16029 void _resolveTestUnit(String code) {
15959 testCode = code; 16030 testCode = code;
15960 testSource = addSource(testCode); 16031 testSource = addSource(testCode);
15961 LibraryElement library = resolve2(testSource); 16032 LibraryElement library = resolve2(testSource);
15962 assertNoErrors(testSource); 16033 assertNoErrors(testSource);
15963 verify([testSource]); 16034 verify([testSource]);
15964 testUnit = resolveCompilationUnit(testSource, library); 16035 testUnit = resolveCompilationUnit(testSource, library);
15965 } 16036 }
15966 } 16037 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698