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

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

Issue 1507883003: fixes #25174, downward inference on list and map initializers with explicit type args (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 796b216ceffa3de3c87ebb3f88f3d25e1ea23bc7..e84e9ce994377f58f2be3ad6ece158aec8c155c2 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -11747,22 +11747,25 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitListLiteral(ListLiteral node) {
DartType contextType = InferenceContext.getType(node);
- if (node.typeArguments == null && contextType is InterfaceType) {
+ List<DartType> targs = null;
+ if (node.typeArguments != null) {
+ targs = node.typeArguments.arguments.map((t) => t.type).toList();
+ } else if (contextType is InterfaceType) {
InterfaceType listD =
typeProvider.listType.substitute4([typeProvider.dynamicType]);
- List<DartType> targs = inferenceContext.matchTypes(listD, contextType);
- if (targs != null &&
- targs.length == 1 &&
- targs.any((t) => !t.isDynamic)) {
- DartType eType = targs[0];
- InterfaceType listT = typeProvider.listType.substitute4([eType]);
- for (Expression child in node.elements) {
- InferenceContext.setType(child, eType);
- }
- InferenceContext.setType(node, listT);
- } else {
- InferenceContext.clearType(node);
+ targs = inferenceContext.matchTypes(listD, contextType);
+ }
+ if (targs != null &&
+ targs.length == 1 &&
+ !targs[0].isDynamic) {
+ DartType eType = targs[0];
+ InterfaceType listT = typeProvider.listType.substitute4([eType]);
+ for (Expression child in node.elements) {
+ InferenceContext.setType(child, eType);
}
+ InferenceContext.setType(node, listT);
+ } else {
+ InferenceContext.clearType(node);
}
super.visitListLiteral(node);
return null;
@@ -11771,24 +11774,27 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitMapLiteral(MapLiteral node) {
DartType contextType = InferenceContext.getType(node);
- if (node.typeArguments == null && contextType is InterfaceType) {
+ List<DartType> targs = null;
+ if (node.typeArguments != null) {
+ targs = node.typeArguments.arguments.map((t) => t.type).toList();
+ } else if (contextType is InterfaceType) {
InterfaceType mapD = typeProvider.mapType
.substitute4([typeProvider.dynamicType, typeProvider.dynamicType]);
- List<DartType> targs = inferenceContext.matchTypes(mapD, contextType);
- if (targs != null &&
- targs.length == 2 &&
- targs.any((t) => !t.isDynamic)) {
- DartType kType = targs[0];
- DartType vType = targs[1];
- InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]);
- for (MapLiteralEntry entry in node.entries) {
- InferenceContext.setType(entry.key, kType);
- InferenceContext.setType(entry.value, vType);
- }
- InferenceContext.setType(node, mapT);
- } else {
- InferenceContext.clearType(node);
- }
+ targs = inferenceContext.matchTypes(mapD, contextType);
+ }
+ if (targs != null &&
+ targs.length == 2 &&
+ targs.any((t) => !t.isDynamic)) {
+ DartType kType = targs[0];
+ DartType vType = targs[1];
+ InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]);
+ for (MapLiteralEntry entry in node.entries) {
+ InferenceContext.setType(entry.key, kType);
+ InferenceContext.setType(entry.value, vType);
+ }
+ InferenceContext.setType(node, mapT);
+ } else {
+ InferenceContext.clearType(node);
}
super.visitMapLiteral(node);
return null;
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698