| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 isSubTypeOf(f1, f2); | 36 isSubTypeOf(f1, f2); |
| 37 | 37 |
| 38 bool isBoolType(DartType t) => t == provider.boolType; | 38 bool isBoolType(DartType t) => t == provider.boolType; |
| 39 bool isDoubleType(DartType t) => t == provider.doubleType; | 39 bool isDoubleType(DartType t) => t == provider.doubleType; |
| 40 bool isIntType(DartType t) => t == provider.intType; | 40 bool isIntType(DartType t) => t == provider.intType; |
| 41 bool isNumType(DartType t) => t == provider.intType.superclass; | 41 bool isNumType(DartType t) => t == provider.intType.superclass; |
| 42 bool isStringType(DartType t) => t == provider.stringType; | 42 bool isStringType(DartType t) => t == provider.stringType; |
| 43 bool isNonNullableType(DartType t) => false; | 43 bool isNonNullableType(DartType t) => false; |
| 44 bool maybeNonNullableType(DartType t) => false; | 44 bool maybeNonNullableType(DartType t) => false; |
| 45 | 45 |
| 46 StaticInfo checkAssignment(Expression expr, DartType t, bool constContext); | 46 StaticInfo checkAssignment(Expression expr, DartType t); |
| 47 | 47 |
| 48 DartType getStaticType(Expression expr) => expr.staticType; | 48 DartType getStaticType(Expression expr) => expr.staticType; |
| 49 | 49 |
| 50 /// Given a type t, if t is an interface type with a call method | 50 /// Given a type t, if t is an interface type with a call method |
| 51 /// defined, return the function type for the call method, otherwise | 51 /// defined, return the function type for the call method, otherwise |
| 52 /// return null. | 52 /// return null. |
| 53 FunctionType getCallMethodType(DartType t) { | 53 FunctionType getCallMethodType(DartType t) { |
| 54 if (t is InterfaceType) { | 54 if (t is InterfaceType) { |
| 55 ClassElement element = t.element; | 55 ClassElement element = t.element; |
| 56 InheritanceManager manager = new InheritanceManager(element.library); | 56 InheritanceManager manager = new InheritanceManager(element.library); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 MissingTypeReporter reportMissingType = null; | 86 MissingTypeReporter reportMissingType = null; |
| 87 | 87 |
| 88 bool isSubTypeOf(DartType t1, DartType t2) { | 88 bool isSubTypeOf(DartType t1, DartType t2) { |
| 89 return t1.isSubtypeOf(t2); | 89 return t1.isSubtypeOf(t2); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool isAssignable(DartType t1, DartType t2) { | 92 bool isAssignable(DartType t1, DartType t2) { |
| 93 return t1.isAssignableTo(t2); | 93 return t1.isAssignableTo(t2); |
| 94 } | 94 } |
| 95 | 95 |
| 96 StaticInfo checkAssignment( | 96 StaticInfo checkAssignment(Expression expr, DartType toType) { |
| 97 Expression expr, DartType toType, bool constContext) { | |
| 98 final fromType = getStaticType(expr); | 97 final fromType = getStaticType(expr); |
| 99 if (!isAssignable(fromType, toType)) { | 98 if (!isAssignable(fromType, toType)) { |
| 100 return new StaticTypeError(this, expr, toType); | 99 return new StaticTypeError(this, expr, toType); |
| 101 } | 100 } |
| 102 return null; | 101 return null; |
| 103 } | 102 } |
| 104 | 103 |
| 105 DartType elementType(Element e) { | 104 DartType elementType(Element e) { |
| 106 return (e as dynamic).type; | 105 return (e as dynamic).type; |
| 107 } | 106 } |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // type system, but allowed in the regular dart type system, since these | 436 // type system, but allowed in the regular dart type system, since these |
| 438 // are likely to succeed. The canonical example is List<dynamic> and | 437 // are likely to succeed. The canonical example is List<dynamic> and |
| 439 // Iterable<T> for some concrete T (e.g. Object). These are unrelated | 438 // Iterable<T> for some concrete T (e.g. Object). These are unrelated |
| 440 // in the restricted system, but List<dynamic> <: Iterable<T> in dart. | 439 // in the restricted system, but List<dynamic> <: Iterable<T> in dart. |
| 441 if (options.relaxedCasts && fromT.isAssignableTo(toT)) { | 440 if (options.relaxedCasts && fromT.isAssignableTo(toT)) { |
| 442 return Coercion.cast(fromT, toT); | 441 return Coercion.cast(fromT, toT); |
| 443 } | 442 } |
| 444 return Coercion.error(); | 443 return Coercion.error(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 StaticInfo checkAssignment(Expression expr, DartType toT, bool constContext) { | 446 StaticInfo checkAssignment(Expression expr, DartType toT) { |
| 448 final fromT = getStaticType(expr); | 447 final fromT = getStaticType(expr); |
| 449 final Coercion c = _coerceTo(fromT, toT); | 448 final Coercion c = _coerceTo(fromT, toT); |
| 450 if (c is Identity) return null; | 449 if (c is Identity) return null; |
| 451 if (c is CoercionError) return new StaticTypeError(this, expr, toT); | 450 if (c is CoercionError) return new StaticTypeError(this, expr, toT); |
| 452 var reason = null; | 451 var reason = null; |
| 453 if (options.inferDownwards) { | 452 if (options.inferDownwards) { |
| 454 var errors = <String>[]; | 453 var errors = <String>[]; |
| 455 var ok = inferrer.inferExpression(expr, toT, errors); | 454 var ok = inferrer.inferExpression(expr, toT, errors); |
| 456 if (ok) return InferredType.create(this, expr, toT); | 455 if (ok) return InferredType.create(this, expr, toT); |
| 457 reason = (errors.isNotEmpty) ? errors.first : null; | 456 reason = (errors.isNotEmpty) ? errors.first : null; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 var entries = e.entries; | 777 var entries = e.entries; |
| 779 bool inferEntry(MapLiteralEntry entry) { | 778 bool inferEntry(MapLiteralEntry entry) { |
| 780 return _inferExpression(entry.key, kType, errors) && | 779 return _inferExpression(entry.key, kType, errors) && |
| 781 _inferExpression(entry.value, vType, errors); | 780 _inferExpression(entry.value, vType, errors); |
| 782 } | 781 } |
| 783 var b = entries.every(inferEntry); | 782 var b = entries.every(inferEntry); |
| 784 if (b) annotateMapLiteral(e, targs); | 783 if (b) annotateMapLiteral(e, targs); |
| 785 return b; | 784 return b; |
| 786 } | 785 } |
| 787 } | 786 } |
| OLD | NEW |