Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart |
| diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart |
| index 3b8cc43bb21099cf28a3ce7f64e80b3c47d88d73..e1db280feb8d01da84ea511fc6c5126ff5d98a77 100644 |
| --- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart |
| +++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart |
| @@ -5,6 +5,7 @@ |
| import 'package:front_end/src/base/instrumentation.dart'; |
| import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; |
| import 'package:front_end/src/fasta/type_inference/type_promotion.dart'; |
| +import 'package:front_end/src/fasta/type_inference/type_schema_environment.dart'; |
|
ahe
2017/05/02 18:32:56
Long line.
Bob Nystrom
2017/05/02 23:22:17
Note that the style specifically allows long lines
|
| import 'package:kernel/ast.dart' |
| show DartType, DynamicType, InterfaceType, Member; |
| import 'package:kernel/core_types.dart'; |
| @@ -61,6 +62,8 @@ abstract class TypeInferrerImpl<S, E, V, F> extends TypeInferrer<S, E, V, F> { |
| final Instrumentation instrumentation; |
| + final TypeSchemaEnvironment typeSchemaEnvironment; |
| + |
| /// Context information for the current closure, or `null` if we are not |
| /// inside a closure. |
| _ClosureContext _closureContext; |
| @@ -68,7 +71,8 @@ abstract class TypeInferrerImpl<S, E, V, F> extends TypeInferrer<S, E, V, F> { |
| TypeInferrerImpl(TypeInferenceEngineImpl<F> engine, this.uri) |
| : coreTypes = engine.coreTypes, |
| strongMode = engine.strongMode, |
| - instrumentation = engine.instrumentation; |
| + instrumentation = engine.instrumentation, |
| + typeSchemaEnvironment = engine.typeSchemaEnvironment; |
| /// Gets the type promoter that should be used to promote types during |
| /// inference. |
| @@ -78,6 +82,25 @@ abstract class TypeInferrerImpl<S, E, V, F> extends TypeInferrer<S, E, V, F> { |
| /// initializer. |
| E getFieldInitializer(F field); |
| + /// Performs the core type inference algorithm for conditional expressions. |
| + /// |
| + /// [typeContext], [typeNeeded], and the return value behave as described in |
| + /// [inferExpression]. |
| + /// |
| + /// [condition], [then], and [otherwise] are the subexpressions. The inferred |
| + /// type is reported via [setStaticType]. |
| + DartType inferConditionalExpression(DartType typeContext, bool typeNeeded, |
| + E condition, E then, E otherwise, void setStaticType(DartType type)) { |
| + inferExpression(condition, coreTypes.boolClass.rawType, false); |
| + // TODO(paulberry): is it correct to pass the context down? |
| + DartType thenType = inferExpression(then, typeContext, true); |
| + DartType otherwiseType = inferExpression(otherwise, typeContext, true); |
| + DartType type = |
| + typeSchemaEnvironment.getLeastUpperBound(thenType, otherwiseType); |
|
Leaf
2017/05/02 23:28:45
This is, I believe, the current behavior of the an
Paul Berry
2017/05/03 17:31:24
Ah, thank you. I've added a TODO comment.
|
| + setStaticType(type); |
| + return typeNeeded ? type : null; |
| + } |
| + |
| /// Performs type inference on the given [expression]. |
| /// |
| /// [typeContext] is the expected type of the expression, based on surrounding |