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

Unified Diff: pkg/analyzer/lib/src/generated/type_system.dart

Issue 2115173002: fix #25220, infer generic type from constructor arguments (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: update tests to be AST summary friendly Created 4 years, 5 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
Index: pkg/analyzer/lib/src/generated/type_system.dart
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index 74e3fd23275d842333244ad6c042ba5fc28fef57..f7efd79d28437fe9cd9e04c80189e4b3e4929b6b 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -167,8 +167,7 @@ class StrongTypeSystemImpl extends TypeSystem {
}
// Try to infer and instantiate the resulting type.
- var resultType =
- inferringTypeSystem._infer(fnType, allowPartialSolution: false);
+ var resultType = inferringTypeSystem._infer(fnType);
// If the instantiation failed (because some type variable constraints
// could not be solved, in other words, we could not find a valid subtype),
@@ -240,14 +239,7 @@ class StrongTypeSystemImpl extends TypeSystem {
argumentTypes[i], correspondingParameterTypes[i]);
}
- // We are okay inferring some type variables and not others.
- //
- // This lets our return type be as precise as possible, which will help
- // make any type information resulting from it more precise.
- //
- // This is simply a heuristic: the code is incorrect, and we'll issue an
- // error on this call, to indicate that types don't match.
- return inferringTypeSystem._infer(fnType, allowPartialSolution: true);
+ return inferringTypeSystem._infer(fnType);
}
/**
@@ -1282,7 +1274,7 @@ class _StrongInferenceTypeSystem extends StrongTypeSystemImpl {
/// Given the constraints that were given by calling [isSubtypeOf], find the
/// instantiation of the generic function that satisfies these constraints.
- FunctionType _infer(FunctionType fnType, {bool allowPartialSolution: false}) {
+ FunctionType _infer(FunctionType fnType) {
List<TypeParameterType> fnTypeParams =
TypeParameterTypeImpl.getTypes(fnType.typeFormals);
@@ -1335,16 +1327,8 @@ class _StrongInferenceTypeSystem extends StrongTypeSystemImpl {
bound.upper.substitute2(inferredTypes, fnTypeParams)) ||
!isSubtypeOf(bound.lower.substitute2(inferredTypes, fnTypeParams),
inferredTypes[i])) {
- // Unless a partial solution was requested, bail.
- if (!allowPartialSolution) {
- return null;
- }
-
- inferredTypes[i] = DynamicTypeImpl.instance;
- if (typeParam.element.bound != null) {
- inferredTypes[i] =
- typeParam.element.bound.substitute2(inferredTypes, fnTypeParams);
- }
+ // Inference failed. Bail.
+ return null;
}
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/static_type_analyzer.dart ('k') | pkg/analyzer/test/generated/strong_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698