Skip to content

Commit

Permalink
Fix for 'member' type of field formal parameter field.
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com, jwren@google.com
BUG=

Review URL: https://codereview.chromium.org//26968005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@28687 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
scheglov@google.com committed Oct 15, 2013
1 parent b385018 commit e795ef6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.dart.engine.element.ConstructorElement;
import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.ElementVisitor;
import com.google.dart.engine.element.FieldFormalParameterElement;
import com.google.dart.engine.element.MethodElement;
import com.google.dart.engine.element.ParameterElement;
import com.google.dart.engine.element.PropertyAccessorElement;
Expand Down Expand Up @@ -46,12 +47,16 @@ public static ParameterElement from(ParameterElement baseParameter, Parameterize
if (baseParameter == null || definingType.getTypeArguments().length == 0) {
return baseParameter;
}
Type baseType = baseParameter.getType();
Type[] argumentTypes = definingType.getTypeArguments();
Type[] parameterTypes = TypeParameterTypeImpl.getTypes(definingType.getTypeParameters());
Type substitutedType = baseType.substitute(argumentTypes, parameterTypes);
if (baseType.equals(substitutedType)) {
return baseParameter;
// Check if parameter type depends on defining type type arguments.
// It is possible that we did not resolve field formal parameter yet, so skip this check for it.
if (!(baseParameter instanceof FieldFormalParameterElement)) {
Type baseType = baseParameter.getType();
Type[] argumentTypes = definingType.getTypeArguments();
Type[] parameterTypes = TypeParameterTypeImpl.getTypes(definingType.getTypeParameters());
Type substitutedType = baseType.substitute(argumentTypes, parameterTypes);
if (baseType.equals(substitutedType)) {
return baseParameter;
}
}
// TODO(brianwilkerson) Consider caching the substituted type in the instance. It would use more
// memory but speed up some operations. We need to see how often the type is being re-computed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public void test_argumentTypeNotAssignable_classWithCall_Function() throws Excep
verify(source);
}

public void test_argumentTypeNotAssignable_fieldFormalParameterElement_member() throws Exception {
Source source = addSource(createSource(//
"class ObjectSink<T> {",
" void sink(T object) {",
" new TimestampedObject<T>(object);",
" }",
"}",
"class TimestampedObject<E> {",
" E object2;",
" TimestampedObject(this.object2);",
"}"));
resolve(source);
assertNoErrors(source);
verify(source);
}

public void test_argumentTypeNotAssignable_invocation_functionParameter_generic()
throws Exception {
Source source = addSource(createSource(//
Expand Down

0 comments on commit e795ef6

Please sign in to comment.