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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/rules.dart

Issue 1405143006: improve static type analysis for `await for` (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.rules; 7 library analyzer.src.task.strong.rules;
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 : provider = provider, 50 : provider = provider,
51 objectMembers = getObjectMemberMap(provider) { 51 objectMembers = getObjectMemberMap(provider) {
52 inferrer = new DownwardsInference(this); 52 inferrer = new DownwardsInference(this);
53 } 53 }
54 54
55 /// Given a type t, if t is an interface type with a call method 55 /// Given a type t, if t is an interface type with a call method
56 /// defined, return the function type for the call method, otherwise 56 /// defined, return the function type for the call method, otherwise
57 /// return null. 57 /// return null.
58 FunctionType getCallMethodType(DartType t) { 58 FunctionType getCallMethodType(DartType t) {
59 if (t is InterfaceType) { 59 if (t is InterfaceType) {
60 ClassElement element = t.element; 60 return t.lookUpMethod("call", null)?.type;
61 InheritanceManager manager = new InheritanceManager(element.library);
62 FunctionType callType = manager.lookupMemberType(t, "call");
63 return callType;
64 } 61 }
65 return null; 62 return null;
66 } 63 }
67 64
68 /// Given an expression, return its type assuming it is 65 /// Given an expression, return its type assuming it is
69 /// in the caller position of a call (that is, accounting 66 /// in the caller position of a call (that is, accounting
70 /// for the possibility of a call method). Returns null 67 /// for the possibility of a call method). Returns null
71 /// if expression is not statically callable. 68 /// if expression is not statically callable.
72 FunctionType getTypeAsCaller(Expression applicand) { 69 FunctionType getTypeAsCaller(Expression applicand) {
73 var t = getStaticType(applicand); 70 var t = getStaticType(applicand);
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 var entries = e.entries; 762 var entries = e.entries;
766 bool inferEntry(MapLiteralEntry entry) { 763 bool inferEntry(MapLiteralEntry entry) {
767 return _inferExpression(entry.key, kType, errors) && 764 return _inferExpression(entry.key, kType, errors) &&
768 _inferExpression(entry.value, vType, errors); 765 _inferExpression(entry.value, vType, errors);
769 } 766 }
770 var b = entries.every(inferEntry); 767 var b = entries.every(inferEntry);
771 if (b) annotateMapLiteral(e, targs); 768 if (b) annotateMapLiteral(e, targs);
772 return b; 769 return b;
773 } 770 }
774 } 771 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698