| 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 library dev_compiler.src.info; | 7 library dev_compiler.src.info; |
| 8 | 8 |
| 9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 // Inference "casts": | 238 // Inference "casts": |
| 239 if (expression is Literal) { | 239 if (expression is Literal) { |
| 240 // fromT should be an exact type - this will almost certainly fail at | 240 // fromT should be an exact type - this will almost certainly fail at |
| 241 // runtime. | 241 // runtime. |
| 242 return new StaticTypeError(rules, expression, toT, reason: reason); | 242 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 243 } | 243 } |
| 244 if (expression is FunctionExpression) { | 244 if (expression is FunctionExpression) { |
| 245 // fromT should be an exact type - this will almost certainly fail at | 245 // fromT should be an exact type - this will almost certainly fail at |
| 246 // runtime. | 246 // runtime. |
| 247 return new InferableClosure(rules, expression, cast); | 247 return new UninferredClosure(rules, expression, cast); |
| 248 } | 248 } |
| 249 if (expression is InstanceCreationExpression) { | 249 if (expression is InstanceCreationExpression) { |
| 250 // fromT should be an exact type - this will almost certainly fail at | 250 // fromT should be an exact type - this will almost certainly fail at |
| 251 // runtime. | 251 // runtime. |
| 252 return new StaticTypeError(rules, expression, toT, reason: reason); | 252 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Composite cast: these are more likely to fail. | 255 // Composite cast: these are more likely to fail. |
| 256 if (!rules.isGroundType(toT)) { | 256 if (!rules.isGroundType(toT)) { |
| 257 // This cast is (probably) due to our different treatment of dynamic. | 257 // This cast is (probably) due to our different treatment of dynamic. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 // | 309 // |
| 310 // Temporary "casts" of allocation sites - literals, constructor invocations, | 310 // Temporary "casts" of allocation sites - literals, constructor invocations, |
| 311 // and closures. These should be handled by contextual inference. In most | 311 // and closures. These should be handled by contextual inference. In most |
| 312 // cases, inference will be sufficient, though in some it may unmask an actual | 312 // cases, inference will be sufficient, though in some it may unmask an actual |
| 313 // error: e.g., | 313 // error: e.g., |
| 314 // List<int> l = [1, 2, 3]; // Inference succeeds | 314 // List<int> l = [1, 2, 3]; // Inference succeeds |
| 315 // List<String> l = [1, 2, 3]; // Inference reveals static type error | 315 // List<String> l = [1, 2, 3]; // Inference reveals static type error |
| 316 // We're marking all as warnings for now. | 316 // We're marking all as warnings for now. |
| 317 // | 317 // |
| 318 | 318 // TODO(vsm,leafp): Remove this. |
| 319 // A "down cast" on a closure literal. | 319 class UninferredClosure extends DownCast { |
| 320 class InferableClosure extends DownCast { | 320 UninferredClosure(TypeRules rules, FunctionExpression expression, Cast cast) |
| 321 InferableClosure(TypeRules rules, FunctionExpression expression, Cast cast) | |
| 322 : super._internal(rules, expression, cast); | 321 : super._internal(rules, expression, cast); |
| 323 | 322 |
| 324 final Level level = Level.WARNING; | 323 final Level level = Level.WARNING; |
| 325 } | 324 } |
| 326 | 325 |
| 327 // | 326 // |
| 328 // Implicit down casts. These are only injected by the compiler by flag. | 327 // Implicit down casts. These are only injected by the compiler by flag. |
| 329 // | 328 // |
| 330 | 329 |
| 331 // A down cast to a non-ground type. These behave differently from standard | 330 // A down cast to a non-ground type. These behave differently from standard |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 : super._internal(rules, expression, wrapper, wrappedType); | 468 : super._internal(rules, expression, wrapper, wrappedType); |
| 470 } | 469 } |
| 471 | 470 |
| 472 class DynamicInvoke extends Conversion { | 471 class DynamicInvoke extends Conversion { |
| 473 DynamicInvoke(TypeRules rules, Expression expression) | 472 DynamicInvoke(TypeRules rules, Expression expression) |
| 474 : super(rules, expression); | 473 : super(rules, expression); |
| 475 | 474 |
| 476 DartType _getConvertedType() => rules.provider.dynamicType; | 475 DartType _getConvertedType() => rules.provider.dynamicType; |
| 477 | 476 |
| 478 String get message => '$expression requires dynamic invoke'; | 477 String get message => '$expression requires dynamic invoke'; |
| 479 Level get level => Level.WARNING; | 478 Level get level => Level.INFO; |
| 480 | 479 |
| 481 accept(AstVisitor visitor) { | 480 accept(AstVisitor visitor) { |
| 482 if (visitor is ConversionVisitor) { | 481 if (visitor is ConversionVisitor) { |
| 483 return visitor.visitDynamicInvoke(this); | 482 return visitor.visitDynamicInvoke(this); |
| 484 } else { | 483 } else { |
| 485 return expression.accept(visitor); | 484 return expression.accept(visitor); |
| 486 } | 485 } |
| 487 } | 486 } |
| 488 } | 487 } |
| 489 | 488 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 for (var cls in declarations.where((d) => d is ClassMirror)) { | 722 for (var cls in declarations.where((d) => d is ClassMirror)) { |
| 724 if (cls.isSubtypeOf(infoMirror)) { | 723 if (cls.isSubtypeOf(infoMirror)) { |
| 725 allTypes.add(cls); | 724 allTypes.add(cls); |
| 726 baseTypes.add(cls.superclass); | 725 baseTypes.add(cls.superclass); |
| 727 } | 726 } |
| 728 } | 727 } |
| 729 allTypes.removeAll(baseTypes); | 728 allTypes.removeAll(baseTypes); |
| 730 return new List<Type>.from(allTypes.map((mirror) => mirror.reflectedType)) | 729 return new List<Type>.from(allTypes.map((mirror) => mirror.reflectedType)) |
| 731 ..sort((t1, t2) => '$t1'.compareTo('$t2')); | 730 ..sort((t1, t2) => '$t1'.compareTo('$t2')); |
| 732 }(); | 731 }(); |
| OLD | NEW |