| 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 /// Defines static information collected by the type checker and used later by | 5 /// Defines static information collected by the type checker and used later by |
| 6 /// emitters to generate code. | 6 /// emitters to generate code. |
| 7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be | 7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be |
| 8 // refactored to fit into analyzer. | 8 // refactored to fit into analyzer. |
| 9 library analyzer.src.task.strong.info; | 9 library analyzer.src.task.strong.info; |
| 10 | 10 |
| 11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | 13 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/src/dart/element/type.dart'; | 14 import 'package:analyzer/src/dart/element/type.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/type_system.dart'; | 16 import 'package:analyzer/src/generated/type_system.dart'; |
| 17 | 17 |
| 18 // A down cast due to a variable declaration to a ground type. E.g., | 18 /// A down cast due to a variable declaration to a ground type: |
| 19 // T x = expr; | 19 /// |
| 20 // where T is ground. We exclude non-ground types as these behave differently | 20 /// T x = expr; |
| 21 // compared to standard Dart. | 21 /// |
| 22 /// where `T` is ground. We exclude non-ground types as these behave |
| 23 /// differently compared to standard Dart. |
| 22 class AssignmentCast extends DownCast { | 24 class AssignmentCast extends DownCast { |
| 23 AssignmentCast(TypeSystem rules, Expression expression, Cast cast) | 25 AssignmentCast(TypeSystem rules, Expression expression, DartType fromType, |
| 24 : super._internal(rules, expression, cast); | 26 DartType toType) |
| 27 : super._internal(rules, expression, fromType, toType); |
| 25 | 28 |
| 26 @override | 29 @override |
| 27 String get name => 'STRONG_MODE_ASSIGNMENT_CAST'; | 30 String get name => 'STRONG_MODE_ASSIGNMENT_CAST'; |
| 28 | 31 |
| 29 toErrorCode() => new HintCode(name, message); | 32 toErrorCode() => new HintCode(name, message); |
| 30 } | 33 } |
| 31 | 34 |
| 32 // Coercion which casts one type to another | |
| 33 class Cast extends Coercion { | |
| 34 Cast(DartType fromType, DartType toType) : super(fromType, toType); | |
| 35 } | |
| 36 | |
| 37 | |
| 38 // TODO(rnystrom): Analyzer no longer produces or uses anything except Cast, | |
| 39 // so this should be eliminated once DDC no longer uses it. | |
| 40 // The abstract type of coercions mapping one type to another. | |
| 41 // This class also exposes static builder functions which | |
| 42 // check for errors and reduce redundant coercions to the identity. | |
| 43 abstract class Coercion { | |
| 44 final DartType fromType; | |
| 45 final DartType toType; | |
| 46 Coercion(this.fromType, this.toType); | |
| 47 static Coercion cast(DartType fromT, DartType toT) => new Cast(fromT, toT); | |
| 48 static Coercion error() => new CoercionError(); | |
| 49 static Coercion identity(DartType type) => new Identity(type); | |
| 50 } | |
| 51 | |
| 52 // The error coercion. This coercion signals that a coercion | |
| 53 // could not be generated. The code generator should not see | |
| 54 // these. | |
| 55 class CoercionError extends Coercion { | |
| 56 CoercionError() : super(null, null); | |
| 57 } | |
| 58 | |
| 59 /// Implicitly injected expression conversion. | 35 /// Implicitly injected expression conversion. |
| 60 abstract class CoercionInfo extends StaticInfo { | 36 abstract class CoercionInfo extends StaticInfo { |
| 61 static const String _propertyName = 'dev_compiler.src.info.CoercionInfo'; | 37 static const String _propertyName = 'dev_compiler.src.info.CoercionInfo'; |
| 62 | 38 |
| 63 final TypeSystem rules; | 39 final TypeSystem rules; |
| 64 | 40 |
| 65 final Expression node; | 41 final Expression node; |
| 66 | 42 |
| 67 CoercionInfo(this.rules, this.node); | 43 CoercionInfo(this.rules, this.node); |
| 68 | 44 |
| 69 DartType get baseType => node.staticType ?? DynamicTypeImpl.instance; | 45 DartType get baseType => node.staticType ?? DynamicTypeImpl.instance; |
| 70 DartType get convertedType; | 46 DartType get convertedType; |
| 71 | 47 |
| 72 String get message; | 48 String get message; |
| 73 DartType get staticType => convertedType; | 49 DartType get staticType => convertedType; |
| 74 | 50 |
| 75 toErrorCode() => new HintCode(name, message); | 51 toErrorCode() => new HintCode(name, message); |
| 76 | 52 |
| 77 /// Gets the coercion info associated with this node. | 53 /// Gets the coercion info associated with this node. |
| 78 static CoercionInfo get(AstNode node) => node.getProperty(_propertyName); | 54 static CoercionInfo get(AstNode node) => node.getProperty(_propertyName); |
| 79 | 55 |
| 80 /// Sets the coercion info associated with this node. | 56 /// Sets the coercion info associated with this node. |
| 81 static CoercionInfo set(AstNode node, CoercionInfo info) { | 57 static CoercionInfo set(AstNode node, CoercionInfo info) { |
| 82 node.setProperty(_propertyName, info); | 58 node.setProperty(_propertyName, info); |
| 83 return info; | 59 return info; |
| 84 } | 60 } |
| 85 } | 61 } |
| 86 | 62 |
| 87 // Base class for all casts from base type to sub type. | 63 /// Base class for all casts from base type to sub type. |
| 88 abstract class DownCast extends CoercionInfo { | 64 abstract class DownCast extends CoercionInfo { |
| 89 Cast _cast; | 65 final DartType _fromType; |
| 66 final DartType _toType; |
| 90 | 67 |
| 91 DownCast._internal(TypeSystem rules, Expression expression, this._cast) | 68 DownCast._internal( |
| 69 TypeSystem rules, Expression expression, this._fromType, this._toType) |
| 92 : super(rules, expression) { | 70 : super(rules, expression) { |
| 93 assert(_cast.toType != baseType && | 71 assert(_toType != baseType && |
| 94 _cast.fromType == baseType && | 72 _fromType == baseType && |
| 95 (baseType.isDynamic || | 73 (baseType.isDynamic || |
| 96 // Call methods make the following non-redundant | 74 // Call methods make the following non-redundant. |
| 97 _cast.toType.isSubtypeOf(baseType) || | 75 _toType.isSubtypeOf(baseType) || |
| 98 baseType.isAssignableTo(_cast.toType))); | 76 baseType.isAssignableTo(_toType))); |
| 99 } | 77 } |
| 100 | 78 |
| 101 @override | 79 @override |
| 102 List<Object> get arguments => [baseType, convertedType]; | 80 List<Object> get arguments => [baseType, convertedType]; |
| 103 | 81 |
| 104 Cast get cast => _cast; | 82 DartType get convertedType => _toType; |
| 105 | |
| 106 DartType get convertedType => _cast.toType; | |
| 107 | 83 |
| 108 @override | 84 @override |
| 109 String get message => 'Unsound implicit cast from {0} to {1}'; | 85 String get message => 'Unsound implicit cast from {0} to {1}'; |
| 110 | 86 |
| 111 // Factory to create correct DownCast variant. | 87 // Factory to create correct DownCast variant. |
| 112 static StaticInfo create( | 88 static StaticInfo create(StrongTypeSystemImpl rules, Expression expression, |
| 113 StrongTypeSystemImpl rules, Expression expression, Cast cast) { | 89 DartType fromType, DartType toType) { |
| 114 final fromT = cast.fromType; | |
| 115 final toT = cast.toType; | |
| 116 | |
| 117 // toT <:_R fromT => to <: fromT | 90 // toT <:_R fromT => to <: fromT |
| 118 // NB: classes with call methods are subtypes of function | 91 // NB: classes with call methods are subtypes of function |
| 119 // types, but the function type is not assignable to the class | 92 // types, but the function type is not assignable to the class |
| 120 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); | 93 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType)); |
| 121 | 94 |
| 122 // Handle null call specially. | 95 // Handle null call specially. |
| 123 if (expression is NullLiteral) { | 96 if (expression is NullLiteral) { |
| 124 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. | 97 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. |
| 125 return new DownCastImplicit(rules, expression, cast); | 98 return new DownCastImplicit(rules, expression, fromType, toType); |
| 126 } | 99 } |
| 127 | 100 |
| 128 // Inference "casts": | 101 // Inference "casts": |
| 129 if (expression is Literal || expression is FunctionExpression) { | 102 if (expression is Literal || expression is FunctionExpression) { |
| 130 // fromT should be an exact type - this will almost certainly fail at | 103 // fromT should be an exact type - this will almost certainly fail at |
| 131 // runtime. | 104 // runtime. |
| 132 return new StaticTypeError(rules, expression, toT); | 105 return new StaticTypeError(rules, expression, toType); |
| 133 } | 106 } |
| 134 | 107 |
| 135 if (expression is InstanceCreationExpression) { | 108 if (expression is InstanceCreationExpression) { |
| 136 ConstructorElement e = expression.staticElement; | 109 ConstructorElement e = expression.staticElement; |
| 137 if (e == null || !e.isFactory) { | 110 if (e == null || !e.isFactory) { |
| 138 // fromT should be an exact type - this will almost certainly fail at | 111 // fromT should be an exact type - this will almost certainly fail at |
| 139 // runtime. | 112 // runtime. |
| 140 return new StaticTypeError(rules, expression, toT); | 113 return new StaticTypeError(rules, expression, toType); |
| 141 } | 114 } |
| 142 } | 115 } |
| 143 | 116 |
| 144 if (StaticInfo.isKnownFunction(expression)) { | 117 if (StaticInfo.isKnownFunction(expression)) { |
| 145 return new StaticTypeError(rules, expression, toT); | 118 return new StaticTypeError(rules, expression, toType); |
| 146 } | 119 } |
| 147 | 120 |
| 148 // TODO(vsm): Change this to an assert when we have generic methods and | 121 // TODO(vsm): Change this to an assert when we have generic methods and |
| 149 // fix TypeRules._coerceTo to disallow implicit sideways casts. | 122 // fix TypeRules._coerceTo to disallow implicit sideways casts. |
| 150 if (!rules.isSubtypeOf(toT, fromT)) { | 123 if (!rules.isSubtypeOf(toType, fromType)) { |
| 151 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); | 124 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType)); |
| 152 return new DownCastComposite(rules, expression, cast); | 125 return new DownCastComposite(rules, expression, fromType, toType); |
| 153 } | 126 } |
| 154 | 127 |
| 155 // Composite cast: these are more likely to fail. | 128 // Composite cast: these are more likely to fail. |
| 156 if (!rules.isGroundType(toT)) { | 129 if (!rules.isGroundType(toType)) { |
| 157 // This cast is (probably) due to our different treatment of dynamic. | 130 // This cast is (probably) due to our different treatment of dynamic. |
| 158 // It may be more likely to fail at runtime. | 131 // It may be more likely to fail at runtime. |
| 159 if (fromT is InterfaceType) { | 132 if (fromType is InterfaceType) { |
| 160 // For class types, we'd like to allow non-generic down casts, e.g., | 133 // For class types, we'd like to allow non-generic down casts, e.g., |
| 161 // Iterable<T> to List<T>. The intuition here is that raw (generic) | 134 // Iterable<T> to List<T>. The intuition here is that raw (generic) |
| 162 // casts are problematic, and we should complain about those. | 135 // casts are problematic, and we should complain about those. |
| 163 var typeArgs = fromT.typeArguments; | 136 var typeArgs = fromType.typeArguments; |
| 164 if (typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic)) { | 137 if (typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic)) { |
| 165 return new DownCastComposite(rules, expression, cast); | 138 return new DownCastComposite(rules, expression, fromType, toType); |
| 166 } | 139 } |
| 167 } else { | 140 } else { |
| 168 return new DownCastComposite(rules, expression, cast); | 141 return new DownCastComposite(rules, expression, fromType, toType); |
| 169 } | 142 } |
| 170 } | 143 } |
| 171 | 144 |
| 172 // Dynamic cast | 145 // Dynamic cast |
| 173 if (fromT.isDynamic) { | 146 if (fromType.isDynamic) { |
| 174 return new DynamicCast(rules, expression, cast); | 147 return new DynamicCast(rules, expression, fromType, toType); |
| 175 } | 148 } |
| 176 | 149 |
| 177 // Assignment cast | 150 // Assignment cast |
| 178 var parent = expression.parent; | 151 var parent = expression.parent; |
| 179 if (parent is VariableDeclaration && (parent.initializer == expression)) { | 152 if (parent is VariableDeclaration && (parent.initializer == expression)) { |
| 180 return new AssignmentCast(rules, expression, cast); | 153 return new AssignmentCast(rules, expression, fromType, toType); |
| 181 } | 154 } |
| 182 | 155 |
| 183 // Other casts | 156 // Other casts |
| 184 return new DownCastImplicit(rules, expression, cast); | 157 return new DownCastImplicit(rules, expression, fromType, toType); |
| 185 } | 158 } |
| 186 } | 159 } |
| 187 | 160 |
| 188 // | 161 /// Implicit down casts. These are only injected by the compiler by flag. |
| 189 // Implicit down casts. These are only injected by the compiler by flag. | 162 /// |
| 190 // | 163 /// A down cast to a non-ground type. These behave differently from standard |
| 191 // A down cast to a non-ground type. These behave differently from standard | 164 /// Dart and may be more likely to fail at runtime. |
| 192 // Dart and may be more likely to fail at runtime. | |
| 193 class DownCastComposite extends DownCast { | 165 class DownCastComposite extends DownCast { |
| 194 DownCastComposite(TypeSystem rules, Expression expression, Cast cast) | 166 DownCastComposite(TypeSystem rules, Expression expression, DartType fromType, |
| 195 : super._internal(rules, expression, cast); | 167 DartType toType) |
| 168 : super._internal(rules, expression, fromType, toType); |
| 196 | 169 |
| 197 @override | 170 @override |
| 198 String get name => 'STRONG_MODE_DOWN_CAST_COMPOSITE'; | 171 String get name => 'STRONG_MODE_DOWN_CAST_COMPOSITE'; |
| 199 | 172 |
| 200 toErrorCode() => new StaticTypeWarningCode(name, message); | 173 toErrorCode() => new StaticTypeWarningCode(name, message); |
| 201 } | 174 } |
| 202 | 175 |
| 203 // A down cast to a non-ground type. These behave differently from standard | 176 /// A down cast to a non-ground type. These behave differently from standard |
| 204 // Dart and may be more likely to fail at runtime. | 177 /// Dart and may be more likely to fail at runtime. |
| 205 class DownCastImplicit extends DownCast { | 178 class DownCastImplicit extends DownCast { |
| 206 DownCastImplicit(TypeSystem rules, Expression expression, Cast cast) | 179 DownCastImplicit(TypeSystem rules, Expression expression, DartType fromType, |
| 207 : super._internal(rules, expression, cast); | 180 DartType toType) |
| 181 : super._internal(rules, expression, fromType, toType); |
| 208 | 182 |
| 209 @override | 183 @override |
| 210 String get name => 'STRONG_MODE_DOWN_CAST_IMPLICIT'; | 184 String get name => 'STRONG_MODE_DOWN_CAST_IMPLICIT'; |
| 211 | 185 |
| 212 toErrorCode() => new HintCode(name, message); | 186 toErrorCode() => new HintCode(name, message); |
| 213 } | 187 } |
| 214 | 188 |
| 215 // A down cast from dynamic to T. | 189 /// A down cast from dynamic to T. |
| 216 class DynamicCast extends DownCast { | 190 class DynamicCast extends DownCast { |
| 217 DynamicCast(TypeSystem rules, Expression expression, Cast cast) | 191 DynamicCast(TypeSystem rules, Expression expression, DartType fromType, |
| 218 : super._internal(rules, expression, cast); | 192 DartType toType) |
| 193 : super._internal(rules, expression, fromType, toType); |
| 219 | 194 |
| 220 @override | 195 @override |
| 221 String get name => 'STRONG_MODE_DYNAMIC_CAST'; | 196 String get name => 'STRONG_MODE_DYNAMIC_CAST'; |
| 222 | 197 |
| 223 toErrorCode() => new HintCode(name, message); | 198 toErrorCode() => new HintCode(name, message); |
| 224 } | 199 } |
| 225 | 200 |
| 226 class DynamicInvoke extends CoercionInfo { | 201 class DynamicInvoke extends CoercionInfo { |
| 227 static const String _propertyName = 'dev_compiler.src.info.DynamicInvoke'; | 202 static const String _propertyName = 'dev_compiler.src.info.DynamicInvoke'; |
| 228 | 203 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 244 | 219 |
| 245 /// Sets whether this node is the target of a dynamic operation. | 220 /// Sets whether this node is the target of a dynamic operation. |
| 246 static bool set(AstNode node, bool value) { | 221 static bool set(AstNode node, bool value) { |
| 247 // Free the storage for things that aren't dynamic. | 222 // Free the storage for things that aren't dynamic. |
| 248 if (value == false) value = null; | 223 if (value == false) value = null; |
| 249 node.setProperty(_propertyName, value); | 224 node.setProperty(_propertyName, value); |
| 250 return value; | 225 return value; |
| 251 } | 226 } |
| 252 } | 227 } |
| 253 | 228 |
| 254 // The identity coercion | 229 /// Standard / unspecialized inferred type. |
| 255 class Identity extends Coercion { | |
| 256 Identity(DartType fromType) : super(fromType, fromType); | |
| 257 } | |
| 258 | |
| 259 // Standard / unspecialized inferred type | |
| 260 class InferredType extends InferredTypeBase { | 230 class InferredType extends InferredTypeBase { |
| 261 InferredType(TypeSystem rules, Expression expression, DartType type) | 231 InferredType(TypeSystem rules, Expression expression, DartType type) |
| 262 : super._internal(rules, expression, type); | 232 : super._internal(rules, expression, type); |
| 263 | 233 |
| 264 @override | 234 @override |
| 265 String get name => 'STRONG_MODE_INFERRED_TYPE'; | 235 String get name => 'STRONG_MODE_INFERRED_TYPE'; |
| 266 | 236 |
| 267 // Factory to create correct InferredType variant. | 237 /// Factory to create correct InferredType variant. |
| 268 static InferredTypeBase create( | 238 static InferredTypeBase create( |
| 269 TypeSystem rules, Expression expression, DartType type) { | 239 TypeSystem rules, Expression expression, DartType type) { |
| 270 // Specialized inference: | 240 // Specialized inference: |
| 271 if (expression is Literal) { | 241 if (expression is Literal) { |
| 272 return new InferredTypeLiteral(rules, expression, type); | 242 return new InferredTypeLiteral(rules, expression, type); |
| 273 } | 243 } |
| 274 if (expression is InstanceCreationExpression) { | 244 if (expression is InstanceCreationExpression) { |
| 275 return new InferredTypeAllocation(rules, expression, type); | 245 return new InferredTypeAllocation(rules, expression, type); |
| 276 } | 246 } |
| 277 if (expression is FunctionExpression) { | 247 if (expression is FunctionExpression) { |
| 278 return new InferredTypeClosure(rules, expression, type); | 248 return new InferredTypeClosure(rules, expression, type); |
| 279 } | 249 } |
| 280 return new InferredType(rules, expression, type); | 250 return new InferredType(rules, expression, type); |
| 281 } | 251 } |
| 282 } | 252 } |
| 283 | 253 |
| 284 // An inferred type for a non-literal allocation site. | 254 /// An inferred type for a non-literal allocation site. |
| 285 class InferredTypeAllocation extends InferredTypeBase { | 255 class InferredTypeAllocation extends InferredTypeBase { |
| 286 InferredTypeAllocation(TypeSystem rules, Expression expression, DartType type) | 256 InferredTypeAllocation(TypeSystem rules, Expression expression, DartType type) |
| 287 : super._internal(rules, expression, type); | 257 : super._internal(rules, expression, type); |
| 288 | 258 |
| 289 @override | 259 @override |
| 290 String get name => 'STRONG_MODE_INFERRED_TYPE_ALLOCATION'; | 260 String get name => 'STRONG_MODE_INFERRED_TYPE_ALLOCATION'; |
| 291 } | 261 } |
| 292 | 262 |
| 293 // An inferred type for the wrapped expression, which may need to be | 263 /// An inferred type for the wrapped expression, which may need to be |
| 294 // reified into the term | 264 /// reified into the term. |
| 295 abstract class InferredTypeBase extends CoercionInfo { | 265 abstract class InferredTypeBase extends CoercionInfo { |
| 296 final DartType _type; | 266 final DartType _type; |
| 297 | 267 |
| 298 InferredTypeBase._internal( | 268 InferredTypeBase._internal( |
| 299 TypeSystem rules, Expression expression, this._type) | 269 TypeSystem rules, Expression expression, this._type) |
| 300 : super(rules, expression); | 270 : super(rules, expression); |
| 301 | 271 |
| 302 @override | 272 @override |
| 303 List get arguments => [node, type]; | 273 List get arguments => [node, type]; |
| 304 DartType get convertedType => type; | 274 DartType get convertedType => type; |
| 305 @override | 275 @override |
| 306 String get message => '{0} has inferred type {1}'; | 276 String get message => '{0} has inferred type {1}'; |
| 307 DartType get type => _type; | 277 DartType get type => _type; |
| 308 | 278 |
| 309 toErrorCode() => new HintCode(name, message); | 279 toErrorCode() => new HintCode(name, message); |
| 310 } | 280 } |
| 311 | 281 |
| 312 // An inferred type for a closure expression | 282 /// An inferred type for a closure expression. |
| 313 class InferredTypeClosure extends InferredTypeBase { | 283 class InferredTypeClosure extends InferredTypeBase { |
| 314 InferredTypeClosure(TypeSystem rules, Expression expression, DartType type) | 284 InferredTypeClosure(TypeSystem rules, Expression expression, DartType type) |
| 315 : super._internal(rules, expression, type); | 285 : super._internal(rules, expression, type); |
| 316 | 286 |
| 317 @override | 287 @override |
| 318 String get name => 'STRONG_MODE_INFERRED_TYPE_CLOSURE'; | 288 String get name => 'STRONG_MODE_INFERRED_TYPE_CLOSURE'; |
| 319 } | 289 } |
| 320 | 290 |
| 321 // An inferred type for a literal expression. | 291 /// An inferred type for a literal expression. |
| 322 class InferredTypeLiteral extends InferredTypeBase { | 292 class InferredTypeLiteral extends InferredTypeBase { |
| 323 InferredTypeLiteral(TypeSystem rules, Expression expression, DartType type) | 293 InferredTypeLiteral(TypeSystem rules, Expression expression, DartType type) |
| 324 : super._internal(rules, expression, type); | 294 : super._internal(rules, expression, type); |
| 325 | 295 |
| 326 @override | 296 @override |
| 327 String get name => 'STRONG_MODE_INFERRED_TYPE_LITERAL'; | 297 String get name => 'STRONG_MODE_INFERRED_TYPE_LITERAL'; |
| 328 } | 298 } |
| 329 | 299 |
| 330 class InvalidFieldOverride extends InvalidOverride { | 300 class InvalidFieldOverride extends InvalidOverride { |
| 331 InvalidFieldOverride(AstNode node, ExecutableElement element, | 301 InvalidFieldOverride(AstNode node, ExecutableElement element, |
| 332 InterfaceType base, DartType subType, DartType baseType) | 302 InterfaceType base, DartType subType, DartType baseType) |
| 333 : super(node, element, base, subType, baseType); | 303 : super(node, element, base, subType, baseType); |
| 334 | 304 |
| 335 String get message => 'Field declaration {3}.{1} cannot be ' | 305 String get message => 'Field declaration {3}.{1} cannot be ' |
| 336 'overridden in {0}.'; | 306 'overridden in {0}.'; |
| 337 | 307 |
| 338 @override | 308 @override |
| 339 String get name => 'STRONG_MODE_INVALID_FIELD_OVERRIDE'; | 309 String get name => 'STRONG_MODE_INVALID_FIELD_OVERRIDE'; |
| 340 } | 310 } |
| 341 | 311 |
| 342 // Invalid override due to incompatible type. I.e., the overridden signature | 312 /// Invalid override due to incompatible type. I.e., the overridden signature |
| 343 // is not compatible with the original. | 313 /// is not compatible with the original. |
| 344 class InvalidMethodOverride extends InvalidOverride { | 314 class InvalidMethodOverride extends InvalidOverride { |
| 345 InvalidMethodOverride(AstNode node, ExecutableElement element, | 315 InvalidMethodOverride(AstNode node, ExecutableElement element, |
| 346 InterfaceType base, FunctionType subType, FunctionType baseType) | 316 InterfaceType base, FunctionType subType, FunctionType baseType) |
| 347 : super(node, element, base, subType, baseType); | 317 : super(node, element, base, subType, baseType); |
| 348 | 318 |
| 349 String get message => _messageHelper('Invalid override'); | 319 String get message => _messageHelper('Invalid override'); |
| 350 | 320 |
| 351 @override | 321 @override |
| 352 String get name => 'STRONG_MODE_INVALID_METHOD_OVERRIDE'; | 322 String get name => 'STRONG_MODE_INVALID_METHOD_OVERRIDE'; |
| 353 } | 323 } |
| 354 | 324 |
| 355 // Invalid override of an instance member of a class. | 325 /// Invalid override of an instance member of a class. |
| 356 abstract class InvalidOverride extends StaticError { | 326 abstract class InvalidOverride extends StaticError { |
| 357 /// Member declaration with the invalid override. | 327 /// Member declaration with the invalid override. |
| 358 final ExecutableElement element; | 328 final ExecutableElement element; |
| 359 | 329 |
| 360 /// Type (class or interface) that provides the base declaration. | 330 /// Type (class or interface) that provides the base declaration. |
| 361 final InterfaceType base; | 331 final InterfaceType base; |
| 362 | 332 |
| 363 /// Actual type of the overridden member. | 333 /// Actual type of the overridden member. |
| 364 final DartType subType; | 334 final DartType subType; |
| 365 | 335 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 super(expression); | 539 super(expression); |
| 570 | 540 |
| 571 @override | 541 @override |
| 572 List<Object> get arguments => [node, baseType, expectedType]; | 542 List<Object> get arguments => [node, baseType, expectedType]; |
| 573 @override | 543 @override |
| 574 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; | 544 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; |
| 575 | 545 |
| 576 @override | 546 @override |
| 577 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; | 547 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; |
| 578 } | 548 } |
| OLD | NEW |