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

Unified Diff: pkg/analyzer/test/src/dart/element/element_test.dart

Issue 2351133004: Fix for out of scope type parameters in members. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/dart/element/element_test.dart
diff --git a/pkg/analyzer/test/src/dart/element/element_test.dart b/pkg/analyzer/test/src/dart/element/element_test.dart
index 97a687a792ebb2c555faa3fea3afad6ac28a2a5b..a1f72b8faba45a6707293b21f5bf7305e7935453 100644
--- a/pkg/analyzer/test/src/dart/element/element_test.dart
+++ b/pkg/analyzer/test/src/dart/element/element_test.dart
@@ -2755,15 +2755,17 @@ class InterfaceTypeImplTest extends EngineTestCase {
expect(typeA.getMethod(methodName), same(methodM));
}
- void test_getMethod_parameterized() {
+ void test_getMethod_parameterized_doesNotUseTypeParameter() {
//
- // class A<E> { E m(E p) {} }
+ // class A<E> { void m() {} }
+ // class B {}
//
ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
+ InterfaceType typeB = ElementFactory.classElement2("B").type;
DartType typeE = classA.type.typeArguments[0];
String methodName = "m";
MethodElementImpl methodM =
- ElementFactory.methodElement(methodName, typeE, [typeE]);
+ ElementFactory.methodElement(methodName, typeB, []);
classA.methods = <MethodElement>[methodM];
methodM.type = new FunctionTypeImpl(methodM);
//
@@ -2775,10 +2777,8 @@ class InterfaceTypeImplTest extends EngineTestCase {
MethodElement method = typeAI.getMethod(methodName);
expect(method, isNotNull);
FunctionType methodType = method.type;
- expect(methodType.returnType, same(typeI));
- List<DartType> parameterTypes = methodType.normalParameterTypes;
- expect(parameterTypes, hasLength(1));
- expect(parameterTypes[0], same(typeI));
+ expect(methodType.typeParameters, [same(typeE.element)]);
+ expect(methodType.typeArguments, [same(typeI)]);
}
void test_getMethod_parameterized_flushCached_whenVersionChanges() {
@@ -2806,6 +2806,34 @@ class InterfaceTypeImplTest extends EngineTestCase {
expect(typeAI.methods.single, isNot(same(method)));
}
+ void test_getMethod_parameterized_usesTypeParameter() {
+ //
+ // class A<E> { E m(E p) {} }
+ //
+ ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
+ DartType typeE = classA.type.typeArguments[0];
+ String methodName = "m";
+ MethodElementImpl methodM =
+ ElementFactory.methodElement(methodName, typeE, [typeE]);
+ classA.methods = <MethodElement>[methodM];
+ methodM.type = new FunctionTypeImpl(methodM);
+ //
+ // A<I>
+ //
+ InterfaceType typeI = ElementFactory.classElement2("I").type;
+ InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA);
+ typeAI.typeArguments = <DartType>[typeI];
+ MethodElement method = typeAI.getMethod(methodName);
+ expect(method, isNotNull);
+ FunctionType methodType = method.type;
+ expect(methodType.typeParameters, [same(typeE.element)]);
+ expect(methodType.typeArguments, [same(typeI)]);
+ expect(methodType.returnType, same(typeI));
+ List<DartType> parameterTypes = methodType.normalParameterTypes;
+ expect(parameterTypes, hasLength(1));
+ expect(parameterTypes[0], same(typeI));
+ }
+
void test_getMethod_unimplemented() {
//
// class A {}
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698