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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.resolver; 5 library engine.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../task/strong/info.dart' show InferredType, StaticInfo; 9 import '../task/strong/info.dart' show InferredType, StaticInfo;
10 import 'ast.dart'; 10 import 'ast.dart';
(...skipping 11729 matching lines...) Expand 10 before | Expand all | Expand 10 after
11740 11740
11741 @override 11741 @override
11742 Object visitLabel(Label node) => null; 11742 Object visitLabel(Label node) => null;
11743 11743
11744 @override 11744 @override
11745 Object visitLibraryIdentifier(LibraryIdentifier node) => null; 11745 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
11746 11746
11747 @override 11747 @override
11748 Object visitListLiteral(ListLiteral node) { 11748 Object visitListLiteral(ListLiteral node) {
11749 DartType contextType = InferenceContext.getType(node); 11749 DartType contextType = InferenceContext.getType(node);
11750 if (node.typeArguments == null && contextType is InterfaceType) { 11750 List<DartType> targs = null;
11751 if (node.typeArguments != null) {
11752 targs = node.typeArguments.arguments.map((t) => t.type).toList();
11753 } else if (contextType is InterfaceType) {
11751 InterfaceType listD = 11754 InterfaceType listD =
11752 typeProvider.listType.substitute4([typeProvider.dynamicType]); 11755 typeProvider.listType.substitute4([typeProvider.dynamicType]);
11753 List<DartType> targs = inferenceContext.matchTypes(listD, contextType); 11756 targs = inferenceContext.matchTypes(listD, contextType);
11754 if (targs != null && 11757 }
11755 targs.length == 1 && 11758 if (targs != null &&
11756 targs.any((t) => !t.isDynamic)) { 11759 targs.length == 1 &&
11757 DartType eType = targs[0]; 11760 !targs[0].isDynamic) {
11758 InterfaceType listT = typeProvider.listType.substitute4([eType]); 11761 DartType eType = targs[0];
11759 for (Expression child in node.elements) { 11762 InterfaceType listT = typeProvider.listType.substitute4([eType]);
11760 InferenceContext.setType(child, eType); 11763 for (Expression child in node.elements) {
11761 } 11764 InferenceContext.setType(child, eType);
11762 InferenceContext.setType(node, listT);
11763 } else {
11764 InferenceContext.clearType(node);
11765 } 11765 }
11766 InferenceContext.setType(node, listT);
11767 } else {
11768 InferenceContext.clearType(node);
11766 } 11769 }
11767 super.visitListLiteral(node); 11770 super.visitListLiteral(node);
11768 return null; 11771 return null;
11769 } 11772 }
11770 11773
11771 @override 11774 @override
11772 Object visitMapLiteral(MapLiteral node) { 11775 Object visitMapLiteral(MapLiteral node) {
11773 DartType contextType = InferenceContext.getType(node); 11776 DartType contextType = InferenceContext.getType(node);
11774 if (node.typeArguments == null && contextType is InterfaceType) { 11777 List<DartType> targs = null;
11778 if (node.typeArguments != null) {
11779 targs = node.typeArguments.arguments.map((t) => t.type).toList();
11780 } else if (contextType is InterfaceType) {
11775 InterfaceType mapD = typeProvider.mapType 11781 InterfaceType mapD = typeProvider.mapType
11776 .substitute4([typeProvider.dynamicType, typeProvider.dynamicType]); 11782 .substitute4([typeProvider.dynamicType, typeProvider.dynamicType]);
11777 List<DartType> targs = inferenceContext.matchTypes(mapD, contextType); 11783 targs = inferenceContext.matchTypes(mapD, contextType);
11778 if (targs != null && 11784 }
11779 targs.length == 2 && 11785 if (targs != null &&
11780 targs.any((t) => !t.isDynamic)) { 11786 targs.length == 2 &&
11781 DartType kType = targs[0]; 11787 targs.any((t) => !t.isDynamic)) {
11782 DartType vType = targs[1]; 11788 DartType kType = targs[0];
11783 InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]); 11789 DartType vType = targs[1];
11784 for (MapLiteralEntry entry in node.entries) { 11790 InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]);
11785 InferenceContext.setType(entry.key, kType); 11791 for (MapLiteralEntry entry in node.entries) {
11786 InferenceContext.setType(entry.value, vType); 11792 InferenceContext.setType(entry.key, kType);
11787 } 11793 InferenceContext.setType(entry.value, vType);
11788 InferenceContext.setType(node, mapT);
11789 } else {
11790 InferenceContext.clearType(node);
11791 } 11794 }
11795 InferenceContext.setType(node, mapT);
11796 } else {
11797 InferenceContext.clearType(node);
11792 } 11798 }
11793 super.visitMapLiteral(node); 11799 super.visitMapLiteral(node);
11794 return null; 11800 return null;
11795 } 11801 }
11796 11802
11797 @override 11803 @override
11798 Object visitMethodDeclaration(MethodDeclaration node) { 11804 Object visitMethodDeclaration(MethodDeclaration node) {
11799 ExecutableElement outerFunction = _enclosingFunction; 11805 ExecutableElement outerFunction = _enclosingFunction;
11800 try { 11806 try {
11801 _enclosingFunction = node.element; 11807 _enclosingFunction = node.element;
(...skipping 4262 matching lines...) Expand 10 before | Expand all | Expand 10 after
16064 nonFields.add(node); 16070 nonFields.add(node);
16065 return null; 16071 return null;
16066 } 16072 }
16067 16073
16068 @override 16074 @override
16069 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 16075 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
16070 16076
16071 @override 16077 @override
16072 Object visitWithClause(WithClause node) => null; 16078 Object visitWithClause(WithClause node) => null;
16073 } 16079 }
OLDNEW
« 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