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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 647f8f49b7fcc6d9e7603c90e662ac65aa7d7254..ecbbb2b99e5724618e4e4fff23a9c702bf92afa7 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -12972,6 +12972,98 @@ class C<T> {
expect(f.staticType.toString(), '<S>(S) → dynamic');
}
+ void test_genericMethod_override() {
+ _resolveTestUnit(r'''
+class C {
+ /*=T*/ f/*<T>*/(/*=T*/ x) => null;
+}
+class D extends C {
+ /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D
+}
+''');
+ SimpleIdentifier f =
+ _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D');
+ MethodElementImpl e = f.staticElement;
+ expect(e.typeParameters.toString(), '[T]');
+ expect(e.type.boundTypeParameters.toString(), '[T]');
+ expect(e.type.toString(), '<T>(T) → T');
+
+ FunctionType ft = e.type.instantiate([typeProvider.stringType]);
+ expect(ft.toString(), '(String) → String');
+ }
+
+ void test_genericMethod_override_bounds() {
+ _resolveTestUnit(r'''
+class A {}
+class B extends A {}
+class C {
+ /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null;
+}
+class D extends C {
+ /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null;
+}
+''');
+ }
+
+ void test_genericMethod_override_invalidReturnType() {
+ Source source = addSource(r'''
+class C {
+ Iterable/*<T>*/ f/*<T>*/(/*=T*/ x) => null;
+}
+class D extends C {
+ String f/*<S>*/(/*=S*/ x) => null;
+}''');
+ // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors
+ // from CodeChecker don't have working equality.
+ List<AnalysisError> errors = analysisContext2.computeErrors(source);
+ expect(errors.map((e) => e.errorCode.name), [
+ 'INVALID_METHOD_OVERRIDE_RETURN_TYPE',
+ 'STRONG_MODE_INVALID_METHOD_OVERRIDE'
+ ]);
+ expect(errors[0].message, contains('Iterable<S>'),
+ reason: 'errors should be in terms of the type parameters '
+ 'at the error location');
+ verify([source]);
+ }
+
+ void test_genericMethod_override_invalidTypeParamBounds() {
+ Source source = addSource(r'''
+class A {}
+class B extends A {}
+class C {
+ /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null;
+}
+class D extends C {
+ /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null;
+}''');
+ // TODO(jmesserly): this is modified code from assertErrors, which we can't
+ // use directly because STRONG_MODE_* errors don't have working equality.
+ List<AnalysisError> errors = analysisContext2.computeErrors(source);
+ expect(errors.map((e) => e.errorCode.name), [
+ 'STRONG_MODE_INVALID_METHOD_OVERRIDE',
+ 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND'
+ ]);
+ verify([source]);
+ }
+
+ void test_genericMethod_override_invalidTypeParamCount() {
+ Source source = addSource(r'''
+class C {
+ /*=T*/ f/*<T>*/(/*=T*/ x) => null;
+}
+class D extends C {
+ /*=S*/ f/*<T, S>*/(/*=T*/ x) => null;
+}''');
+ // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors
+ // from CodeChecker don't have working equality.
+ List<AnalysisError> errors = analysisContext2.computeErrors(source);
+ expect(errors.map((e) => e.errorCode.name), [
+ 'STRONG_MODE_INVALID_METHOD_OVERRIDE',
+ 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS'
+ ]);
+ verify([source]);
+ }
+
void test_pseudoGeneric_max_doubleDouble() {
String code = r'''
import 'dart:math';
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698