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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Issue 2904133002: Fix type inference of redirecting factory constructor invocations. (Closed)
Patch Set: Created 3 years, 7 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 /// This file declares a "shadow hierarchy" of concrete classes which extend 5 /// This file declares a "shadow hierarchy" of concrete classes which extend
6 /// the kernel class hierarchy, adding methods and fields needed by the 6 /// the kernel class hierarchy, adding methods and fields needed by the
7 /// BodyBuilder. 7 /// BodyBuilder.
8 /// 8 ///
9 /// Instances of these classes may be created using the factory methods in 9 /// Instances of these classes may be created using the factory methods in
10 /// `ast_factory.dart`. 10 /// `ast_factory.dart`.
(...skipping 10 matching lines...) Expand all
21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; 21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart';
22 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ; 22 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ;
23 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; 23 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart';
24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart'; 24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart';
25 import 'package:front_end/src/fasta/type_inference/type_schema.dart'; 25 import 'package:front_end/src/fasta/type_inference/type_schema.dart';
26 import 'package:front_end/src/fasta/type_inference/type_schema_elimination.dart' ; 26 import 'package:front_end/src/fasta/type_inference/type_schema_elimination.dart' ;
27 import 'package:kernel/ast.dart'; 27 import 'package:kernel/ast.dart';
28 import 'package:kernel/frontend/accessors.dart'; 28 import 'package:kernel/frontend/accessors.dart';
29 import 'package:kernel/type_algebra.dart'; 29 import 'package:kernel/type_algebra.dart';
30 30
31 /// Computes the return type of a (possibly factory) constructor.
32 InterfaceType computeConstructorReturnType(Member constructor) {
33 if (constructor is Constructor) {
34 return constructor.enclosingClass.thisType;
35 } else {
36 return computeFactoryConstructorReturnType(constructor);
37 }
38 }
39
31 /// Computes the return type of a factory constructor. 40 /// Computes the return type of a factory constructor.
32 /// 41 ///
33 /// Note that we can't just use `constructor.function.functionType.returnType`, 42 /// Note that we can't just use `constructor.function.functionType.returnType`,
34 /// because that's `dynamic` for factory constructors. TODO(paulberry): 43 /// because that's `dynamic` for factory constructors. TODO(paulberry):
35 /// investigate whether this can be changed. 44 /// investigate whether this can be changed.
36 InterfaceType computeFactoryConstructorReturnType(Procedure constructor) { 45 InterfaceType computeFactoryConstructorReturnType(Procedure constructor) {
37 var returnType = constructor.enclosingClass.thisType; 46 var returnType = constructor.enclosingClass.thisType;
38 if (constructor.enclosingClass.typeParameters.isNotEmpty) { 47 if (constructor.enclosingClass.typeParameters.isNotEmpty) {
39 // target.enclosingClass.typeParameters is not the same as 48 // target.enclosingClass.typeParameters is not the same as
40 // target.function.functionType.typeParameters, so we have to substitute. 49 // target.function.functionType.typeParameters, so we have to substitute.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 staticType = type; 246 staticType = type;
238 var inferredType = typeNeeded ? type : null; 247 var inferredType = typeNeeded ? type : null;
239 inferrer.listener.conditionalExpressionExit(this, inferredType); 248 inferrer.listener.conditionalExpressionExit(this, inferredType);
240 return inferredType; 249 return inferredType;
241 } 250 }
242 } 251 }
243 252
244 /// Shadow object for [ConstructorInvocation]. 253 /// Shadow object for [ConstructorInvocation].
245 class KernelConstructorInvocation extends ConstructorInvocation 254 class KernelConstructorInvocation extends ConstructorInvocation
246 implements KernelExpression { 255 implements KernelExpression {
247 KernelConstructorInvocation(Constructor target, Arguments arguments, 256 final Member _initialTarget;
257
258 KernelConstructorInvocation(
259 Constructor target, this._initialTarget, Arguments arguments,
248 {bool isConst: false}) 260 {bool isConst: false})
249 : super(target, arguments, isConst: isConst); 261 : super(target, arguments, isConst: isConst);
250 262
251 KernelConstructorInvocation.byReference(
252 Reference targetReference, Arguments arguments)
253 : super.byReference(targetReference, arguments);
254
255 @override 263 @override
256 DartType _inferExpression( 264 DartType _inferExpression(
257 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 265 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
258 typeNeeded = 266 typeNeeded =
259 inferrer.listener.constructorInvocationEnter(this, typeContext) || 267 inferrer.listener.constructorInvocationEnter(this, typeContext) ||
260 typeNeeded; 268 typeNeeded;
261 var inferredType = inferrer.inferInvocation( 269 var inferredType = inferrer.inferInvocation(
262 typeContext, 270 typeContext,
263 typeNeeded, 271 typeNeeded,
264 fileOffset, 272 fileOffset,
265 target.function.functionType, 273 _initialTarget.function.functionType,
266 target.enclosingClass.thisType, 274 computeConstructorReturnType(_initialTarget),
267 arguments); 275 arguments);
268 inferrer.listener.constructorInvocationExit(this, inferredType); 276 inferrer.listener.constructorInvocationExit(this, inferredType);
269 return inferredType; 277 return inferredType;
270 } 278 }
271 } 279 }
272 280
273 /// Shadow object for [DirectMethodInvocation]. 281 /// Shadow object for [DirectMethodInvocation].
274 class KernelDirectMethodInvocation extends DirectMethodInvocation 282 class KernelDirectMethodInvocation extends DirectMethodInvocation
275 implements KernelExpression { 283 implements KernelExpression {
276 KernelDirectMethodInvocation( 284 KernelDirectMethodInvocation(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 inferrer.listener.expressionStatementEnter(this); 368 inferrer.listener.expressionStatementEnter(this);
361 inferrer.inferExpression(expression, null, false); 369 inferrer.inferExpression(expression, null, false);
362 inferrer.listener.expressionStatementExit(this); 370 inferrer.listener.expressionStatementExit(this);
363 } 371 }
364 } 372 }
365 373
366 /// Shadow object for [StaticInvocation] when the procedure being invoked is a 374 /// Shadow object for [StaticInvocation] when the procedure being invoked is a
367 /// factory constructor. 375 /// factory constructor.
368 class KernelFactoryConstructorInvocation extends StaticInvocation 376 class KernelFactoryConstructorInvocation extends StaticInvocation
369 implements KernelExpression { 377 implements KernelExpression {
370 KernelFactoryConstructorInvocation(Procedure target, Arguments arguments, 378 final Member _initialTarget;
379
380 KernelFactoryConstructorInvocation(
381 Procedure target, this._initialTarget, Arguments arguments,
371 {bool isConst: false}) 382 {bool isConst: false})
372 : super(target, arguments, isConst: isConst); 383 : super(target, arguments, isConst: isConst);
373 384
374 @override 385 @override
375 DartType _inferExpression( 386 DartType _inferExpression(
376 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 387 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
377 typeNeeded = 388 typeNeeded =
378 inferrer.listener.constructorInvocationEnter(this, typeContext) || 389 inferrer.listener.constructorInvocationEnter(this, typeContext) ||
379 typeNeeded; 390 typeNeeded;
380 InterfaceType returnType = computeFactoryConstructorReturnType(target); 391 var inferredType = inferrer.inferInvocation(
381 var inferredType = inferrer.inferInvocation(typeContext, typeNeeded, 392 typeContext,
382 fileOffset, target.function.functionType, returnType, arguments); 393 typeNeeded,
394 fileOffset,
395 _initialTarget.function.functionType,
396 computeConstructorReturnType(_initialTarget),
397 arguments);
383 inferrer.listener.constructorInvocationExit(this, inferredType); 398 inferrer.listener.constructorInvocationExit(this, inferredType);
384 return inferredType; 399 return inferredType;
385 } 400 }
386 } 401 }
387 402
388 /// Concrete shadow object representing a field in kernel form. 403 /// Concrete shadow object representing a field in kernel form.
389 class KernelField extends Field { 404 class KernelField extends Field {
390 bool _implicitlyTyped = true; 405 bool _implicitlyTyped = true;
391 406
392 FieldNode _fieldNode; 407 FieldNode _fieldNode;
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 closureContext.isAsync 1466 closureContext.isAsync
1452 ? inferrer.coreTypes.streamClass 1467 ? inferrer.coreTypes.streamClass
1453 : inferrer.coreTypes.iterableClass); 1468 : inferrer.coreTypes.iterableClass);
1454 } 1469 }
1455 var inferredType = inferrer.inferExpression( 1470 var inferredType = inferrer.inferExpression(
1456 expression, typeContext, closureContext != null); 1471 expression, typeContext, closureContext != null);
1457 closureContext.handleYield(inferrer, isYieldStar, inferredType); 1472 closureContext.handleYield(inferrer, isYieldStar, inferredType);
1458 inferrer.listener.yieldStatementExit(this); 1473 inferrer.listener.yieldStatementExit(this);
1459 } 1474 }
1460 } 1475 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/test/fasta/kompile.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698