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

Side by Side Diff: lib/src/checker/rules.dart

Issue 1055923002: Don't call dinvoke on Object methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Fix for sealed types Created 5 years, 8 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 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 library dev_compiler.src.checker.rules; 5 library dev_compiler.src.checker.rules;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/resolver.dart'; 9 import 'package:analyzer/src/generated/resolver.dart';
10 10
(...skipping 26 matching lines...) Expand all
37 bool maybeNonNullableType(DartType t) => false; 37 bool maybeNonNullableType(DartType t) => false;
38 38
39 StaticInfo checkAssignment(Expression expr, DartType t, bool constContext); 39 StaticInfo checkAssignment(Expression expr, DartType t, bool constContext);
40 40
41 DartType getStaticType(Expression expr) => expr.staticType; 41 DartType getStaticType(Expression expr) => expr.staticType;
42 42
43 DartType elementType(Element e); 43 DartType elementType(Element e);
44 44
45 bool isDynamic(DartType t); 45 bool isDynamic(DartType t);
46 bool isDynamicTarget(Expression expr); 46 bool isDynamicTarget(Expression expr);
47 bool isDynamicGet(Expression expr); 47 bool isDynamicGet(Expression target, SimpleIdentifier name);
48 bool isDynamicCall(Expression call); 48 bool isDynamicCall(Expression call);
49 } 49 }
50 50
51 class DartRules extends TypeRules { 51 class DartRules extends TypeRules {
52 DartRules(TypeProvider provider) : super(provider); 52 DartRules(TypeProvider provider) : super(provider);
53 53
54 bool isSubTypeOf(DartType t1, DartType t2) { 54 bool isSubTypeOf(DartType t1, DartType t2) {
55 return t1.isSubtypeOf(t2); 55 return t1.isSubtypeOf(t2);
56 } 56 }
57 57
(...skipping 10 matching lines...) Expand all
68 return null; 68 return null;
69 } 69 }
70 70
71 DartType elementType(Element e) { 71 DartType elementType(Element e) {
72 return (e as dynamic).type; 72 return (e as dynamic).type;
73 } 73 }
74 74
75 /// By default, all invocations are dynamic in Dart. 75 /// By default, all invocations are dynamic in Dart.
76 bool isDynamic(DartType t) => true; 76 bool isDynamic(DartType t) => true;
77 bool isDynamicTarget(Expression expr) => true; 77 bool isDynamicTarget(Expression expr) => true;
78 bool isDynamicGet(Expression expr) => true; 78 bool isDynamicGet(Expression target, SimpleIdentifier name) => true;
79 bool isDynamicCall(Expression call) => true; 79 bool isDynamicCall(Expression call) => true;
80 } 80 }
81 81
82 class RestrictedRules extends TypeRules { 82 class RestrictedRules extends TypeRules {
83 final CheckerReporter _reporter; 83 final CheckerReporter _reporter;
84 final RulesOptions options; 84 final RulesOptions options;
85 final List<DartType> _nonnullableTypes; 85 final List<DartType> _nonnullableTypes;
86 DownwardsInference inferrer; 86 DownwardsInference inferrer;
87 87
88 DartType _typeFromName(String name) { 88 DartType _typeFromName(String name) {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 523 }
524 524
525 bool isDynamic(DartType t) => options.ignoreTypes || t.isDynamic; 525 bool isDynamic(DartType t) => options.ignoreTypes || t.isDynamic;
526 526
527 /// Returns `true` if the target expression is dynamic. 527 /// Returns `true` if the target expression is dynamic.
528 bool isDynamicTarget(Expression expr) => 528 bool isDynamicTarget(Expression expr) =>
529 options.ignoreTypes || getStaticType(expr).isDynamic; 529 options.ignoreTypes || getStaticType(expr).isDynamic;
530 530
531 /// Returns `true` if the expression is a dynamic property access or prefixed 531 /// Returns `true` if the expression is a dynamic property access or prefixed
532 /// identifier. 532 /// identifier.
533 bool isDynamicGet(Expression expr) { 533 bool isDynamicGet(Expression target, SimpleIdentifier name) {
534 if (options.ignoreTypes) return true; 534 if (options.ignoreTypes) return true;
535 var t = getStaticType(expr); 535 if (!name.staticType.isDynamic) return false;
536 var t = getStaticType(target);
536 // TODO(jmesserly): we should not allow all property gets on `Function` 537 // TODO(jmesserly): we should not allow all property gets on `Function`
537 return t.isDynamic || t.isDartCoreFunction; 538 return t.isDynamic || t.isDartCoreFunction;
538 } 539 }
539 540
540 /// Returns `true` if the expression is a dynamic function call or method 541 /// Returns `true` if the expression is a dynamic function call or method
541 /// invocation. 542 /// invocation.
542 bool isDynamicCall(Expression call) { 543 bool isDynamicCall(Expression call) {
543 if (options.ignoreTypes) return true; 544 if (options.ignoreTypes) return true;
544 var t = getStaticType(call); 545 var t = getStaticType(call);
545 // TODO(jmesserly): fix handling of types with `call` methods. These are not 546 // TODO(jmesserly): fix handling of types with `call` methods. These are not
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 var entries = e.entries; 829 var entries = e.entries;
829 bool inferEntry(MapLiteralEntry entry) { 830 bool inferEntry(MapLiteralEntry entry) {
830 return _inferExpression(entry.key, kType, errors) && 831 return _inferExpression(entry.key, kType, errors) &&
831 _inferExpression(entry.value, vType, errors); 832 _inferExpression(entry.value, vType, errors);
832 } 833 }
833 var b = entries.every(inferEntry); 834 var b = entries.every(inferEntry);
834 if (b) annotateMapLiteral(e, targs); 835 if (b) annotateMapLiteral(e, targs);
835 return b; 836 return b;
836 } 837 }
837 } 838 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698