@@ -1015,6 +1015,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
1015
1015
} else if (staticElement is VariableElement ) {
1016
1016
staticType = staticElement.type;
1017
1017
}
1018
+ if (_strongMode) {
1019
+ staticType = _inferGenericInstantiationFromContext (
1020
+ InferenceContext .getType (node), staticType);
1021
+ }
1018
1022
if (! (_strongMode &&
1019
1023
_inferObjectAccess (node, staticType, prefixedIdentifier))) {
1020
1024
_recordStaticType (prefixedIdentifier, staticType);
@@ -1144,6 +1148,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
1144
1148
} else {
1145
1149
// TODO(brianwilkerson) Report this internal error.
1146
1150
}
1151
+ if (_strongMode) {
1152
+ staticType = _inferGenericInstantiationFromContext (
1153
+ InferenceContext .getType (node), staticType);
1154
+ }
1147
1155
if (! (_strongMode && _inferObjectAccess (node, staticType, propertyName))) {
1148
1156
_recordStaticType (propertyName, staticType);
1149
1157
_recordStaticType (node, staticType);
@@ -1244,6 +1252,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
1244
1252
} else {
1245
1253
staticType = _dynamicType;
1246
1254
}
1255
+ if (_strongMode) {
1256
+ staticType = _inferGenericInstantiationFromContext (
1257
+ InferenceContext .getType (node), staticType);
1258
+ }
1247
1259
_recordStaticType (node, staticType);
1248
1260
// TODO(brianwilkerson) I think we want to repeat the logic above using the
1249
1261
// propagated element to get another candidate for the propagated type.
@@ -1882,6 +1894,21 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
1882
1894
return false ;
1883
1895
}
1884
1896
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
+
1885
1912
/**
1886
1913
* Given a method invocation [node] , attempt to infer a better
1887
1914
* type for the result if it is an inline JS invocation
0 commit comments