fixes #24713, remove old generic substitution code in _getTypeOfProperty

it looks like some old code was hanging around that tried to substitute generic type parameters by name. This is unnecessary because we already have a substituted type at this point, and the type variable we were substituting had no relationship at all with the parameter. After removing the code, all tests seem to be passing.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/1409143009 .
This commit is contained in:
John Messerly
2015-10-24 12:48:53 -07:00
parent c43f292dd9
commit 396ed51cf0
2 changed files with 30 additions and 40 deletions
@@ -888,7 +888,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
} else if (staticElement is MethodElement) {
staticType = staticElement.type;
} else if (staticElement is PropertyAccessorElement) {
staticType = _getTypeOfProperty(staticElement, node.prefix.staticType);
staticType = _getTypeOfProperty(staticElement);
propagatedType =
_getPropertyPropagatedType(staticElement, propagatedType);
} else if (staticElement is ExecutableElement) {
@@ -921,8 +921,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
} else if (propagatedElement is MethodElement) {
propagatedType = propagatedElement.type;
} else if (propagatedElement is PropertyAccessorElement) {
propagatedType =
_getTypeOfProperty(propagatedElement, node.prefix.staticType);
propagatedType = _getTypeOfProperty(propagatedElement);
propagatedType =
_getPropertyPropagatedType(propagatedElement, propagatedType);
} else if (propagatedElement is ExecutableElement) {
@@ -1024,9 +1023,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
if (staticElement is MethodElement) {
staticType = staticElement.type;
} else if (staticElement is PropertyAccessorElement) {
Expression realTarget = node.realTarget;
staticType = _getTypeOfProperty(staticElement,
realTarget != null ? _getStaticType(realTarget) : null);
staticType = _getTypeOfProperty(staticElement);
} else {
// TODO(brianwilkerson) Report this internal error.
}
@@ -1040,8 +1037,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
propagatedType = propagatedElement.type;
} else if (propagatedElement is PropertyAccessorElement) {
Expression realTarget = node.realTarget;
propagatedType = _getTypeOfProperty(
propagatedElement, realTarget != null ? realTarget.bestType : null);
propagatedType = _getTypeOfProperty(propagatedElement);
} else {
// TODO(brianwilkerson) Report this internal error.
}
@@ -1117,7 +1113,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
} else if (element is MethodElement) {
staticType = element.type;
} else if (element is PropertyAccessorElement) {
staticType = _getTypeOfProperty(element, null);
staticType = _getTypeOfProperty(element);
} else if (element is ExecutableElement) {
staticType = element.type;
} else if (element is TypeParameterElement) {
@@ -1628,14 +1624,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
* Return the type that should be recorded for a node that resolved to the given accessor.
*
* @param accessor the accessor that the node resolved to
* @param context if the accessor element has context [by being the RHS of a
* [PrefixedIdentifier] or [PropertyAccess]], and the return type of the
* accessor is a parameter type, then the type of the LHS can be used to get more
* specific type information
* @return the type that should be recorded for a node that resolved to the given accessor
*/
DartType _getTypeOfProperty(
PropertyAccessorElement accessor, DartType context) {
DartType _getTypeOfProperty(PropertyAccessorElement accessor) {
FunctionType functionType = accessor.type;
if (functionType == null) {
// TODO(brianwilkerson) Report this internal error. This happens when we
@@ -1658,29 +1649,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
return _dynamicType;
}
DartType returnType = functionType.returnType;
if (returnType is TypeParameterType && context is InterfaceType) {
// if the return type is a TypeParameter, we try to use the context [that
// the function is being called on] to get a more accurate returnType type
InterfaceType interfaceTypeContext = context;
// Type[] argumentTypes = interfaceTypeContext.getTypeArguments();
List<TypeParameterElement> typeParameterElements =
interfaceTypeContext.element != null
? interfaceTypeContext.element.typeParameters
: null;
if (typeParameterElements != null) {
for (int i = 0; i < typeParameterElements.length; i++) {
TypeParameterElement typeParameterElement = typeParameterElements[i];
if (returnType.name == typeParameterElement.name) {
return interfaceTypeContext.typeArguments[i];
}
}
// TODO(jwren) troubleshoot why call to substitute doesn't work
// Type[] parameterTypes = TypeParameterTypeImpl.getTypes(parameterElements);
// return returnType.substitute(argumentTypes, parameterTypes);
}
}
return returnType;
return functionType.returnType;
}
/**
@@ -1699,8 +1668,8 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
LocalVariableElementImpl element = loopVariable.element;
DartType exprType = expr.staticType;
DartType targetType = (loop.awaitKeyword == null)
? _typeProvider.iterableType
: _typeProvider.streamType;
? _typeProvider.iterableType
: _typeProvider.streamType;
DartType iteratedType = _findIteratedType(exprType, targetType);
if (element != null && iteratedType != null) {
element.type = iteratedType;
@@ -832,6 +832,27 @@ class A {
verify([source]);
}
// https://github.com/dart-lang/sdk/issues/24713
void test_returnOfInvalidType_not_issued_for_valid_generic_return() {
Source source = addSource(r'''
abstract class F<T, U> {
U get value;
}
abstract class G<T> {
T test(F<int, T> arg) => arg.value;
}
abstract class H<S> {
S test(F<int, S> arg) => arg.value;
}
void main() { }''');
computeLibrarySourceErrors(source);
assertNoErrors(source);
verify([source]);
}
void test_returnOfInvalidType_void() {
Source source = addSource("void f() { return 42; }");
computeLibrarySourceErrors(source);