Skip to content

Commit eb28d6e

Browse files
author
John Messerly
committed
fix #25619 - downward inference on generic function tear-offs
[email protected] Review URL: https://codereview.chromium.org/1644403005 .
1 parent 3319366 commit eb28d6e

File tree

3 files changed

+313
-127
lines changed

3 files changed

+313
-127
lines changed

pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
10151015
} else if (staticElement is VariableElement) {
10161016
staticType = staticElement.type;
10171017
}
1018+
if (_strongMode) {
1019+
staticType = _inferGenericInstantiationFromContext(
1020+
InferenceContext.getType(node), staticType);
1021+
}
10181022
if (!(_strongMode &&
10191023
_inferObjectAccess(node, staticType, prefixedIdentifier))) {
10201024
_recordStaticType(prefixedIdentifier, staticType);
@@ -1144,6 +1148,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
11441148
} else {
11451149
// TODO(brianwilkerson) Report this internal error.
11461150
}
1151+
if (_strongMode) {
1152+
staticType = _inferGenericInstantiationFromContext(
1153+
InferenceContext.getType(node), staticType);
1154+
}
11471155
if (!(_strongMode && _inferObjectAccess(node, staticType, propertyName))) {
11481156
_recordStaticType(propertyName, staticType);
11491157
_recordStaticType(node, staticType);
@@ -1244,6 +1252,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
12441252
} else {
12451253
staticType = _dynamicType;
12461254
}
1255+
if (_strongMode) {
1256+
staticType = _inferGenericInstantiationFromContext(
1257+
InferenceContext.getType(node), staticType);
1258+
}
12471259
_recordStaticType(node, staticType);
12481260
// TODO(brianwilkerson) I think we want to repeat the logic above using the
12491261
// propagated element to get another candidate for the propagated type.
@@ -1882,6 +1894,21 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
18821894
return false;
18831895
}
18841896

1897+
/**
1898+
* Given an uninstantiated generic type, try to infer the instantiated generic
1899+
* type from the surrounding context.
1900+
*/
1901+
DartType _inferGenericInstantiationFromContext(
1902+
DartType context, DartType type) {
1903+
TypeSystem ts = _typeSystem;
1904+
if (context is FunctionType &&
1905+
type is FunctionType &&
1906+
ts is StrongTypeSystemImpl) {
1907+
return ts.inferFunctionTypeInstantiation(_typeProvider, context, type);
1908+
}
1909+
return type;
1910+
}
1911+
18851912
/**
18861913
* Given a method invocation [node], attempt to infer a better
18871914
* type for the result if it is an inline JS invocation

0 commit comments

Comments
 (0)