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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index 061a017a18fed151300189955e51f15c2c76ef71..814411222674bd7a8339af4e3a1724aec845fb66 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -28,6 +28,15 @@ import 'package:kernel/ast.dart';
import 'package:kernel/frontend/accessors.dart';
import 'package:kernel/type_algebra.dart';
+/// Computes the return type of a (possibly factory) constructor.
+InterfaceType computeConstructorReturnType(Member constructor) {
+ if (constructor is Constructor) {
+ return constructor.enclosingClass.thisType;
+ } else {
+ return computeFactoryConstructorReturnType(constructor);
+ }
+}
+
/// Computes the return type of a factory constructor.
///
/// Note that we can't just use `constructor.function.functionType.returnType`,
@@ -244,14 +253,13 @@ class KernelConditionalExpression extends ConditionalExpression
/// Shadow object for [ConstructorInvocation].
class KernelConstructorInvocation extends ConstructorInvocation
implements KernelExpression {
- KernelConstructorInvocation(Constructor target, Arguments arguments,
+ final Member _initialTarget;
+
+ KernelConstructorInvocation(
+ Constructor target, this._initialTarget, Arguments arguments,
{bool isConst: false})
: super(target, arguments, isConst: isConst);
- KernelConstructorInvocation.byReference(
- Reference targetReference, Arguments arguments)
- : super.byReference(targetReference, arguments);
-
@override
DartType _inferExpression(
KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
@@ -262,8 +270,8 @@ class KernelConstructorInvocation extends ConstructorInvocation
typeContext,
typeNeeded,
fileOffset,
- target.function.functionType,
- target.enclosingClass.thisType,
+ _initialTarget.function.functionType,
+ computeConstructorReturnType(_initialTarget),
arguments);
inferrer.listener.constructorInvocationExit(this, inferredType);
return inferredType;
@@ -367,7 +375,10 @@ class KernelExpressionStatement extends ExpressionStatement
/// factory constructor.
class KernelFactoryConstructorInvocation extends StaticInvocation
implements KernelExpression {
- KernelFactoryConstructorInvocation(Procedure target, Arguments arguments,
+ final Member _initialTarget;
+
+ KernelFactoryConstructorInvocation(
+ Procedure target, this._initialTarget, Arguments arguments,
{bool isConst: false})
: super(target, arguments, isConst: isConst);
@@ -377,9 +388,13 @@ class KernelFactoryConstructorInvocation extends StaticInvocation
typeNeeded =
inferrer.listener.constructorInvocationEnter(this, typeContext) ||
typeNeeded;
- InterfaceType returnType = computeFactoryConstructorReturnType(target);
- var inferredType = inferrer.inferInvocation(typeContext, typeNeeded,
- fileOffset, target.function.functionType, returnType, arguments);
+ var inferredType = inferrer.inferInvocation(
+ typeContext,
+ typeNeeded,
+ fileOffset,
+ _initialTarget.function.functionType,
+ computeConstructorReturnType(_initialTarget),
+ arguments);
inferrer.listener.constructorInvocationExit(this, inferredType);
return inferredType;
}
« 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