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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart

Issue 2916533003: Set return type of factory constructors properly. (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
Index: pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart
index 210e5a11886da11fda5cb602790742f26eeabbcf..69f9ef377e0c17fa4f8c3f137bb4571d828c5a3b 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart
@@ -8,6 +8,7 @@ import 'package:kernel/ast.dart'
show
Arguments,
AsyncMarker,
+ Class,
Constructor,
ConstructorInvocation,
DartType,
@@ -28,12 +29,14 @@ import 'package:kernel/ast.dart'
StringLiteral,
SuperInitializer,
TypeParameter,
+ TypeParameterType,
VariableDeclaration,
VariableGet,
VoidType,
setParents;
-import 'package:kernel/type_algebra.dart' show containsTypeVariable, substitute;
+import 'package:kernel/type_algebra.dart'
+ show Substitution, containsTypeVariable, substitute;
import '../errors.dart' show internalError;
@@ -122,6 +125,22 @@ abstract class KernelFunctionBuilder
}
if (!isConstructor && !isInstanceMember && parent is ClassBuilder) {
List<TypeParameter> typeParameters = parent.target.typeParameters;
+ if (kind == ProcedureKind.Factory) {
ahe 2017/06/01 09:10:08 This I have a different solution for.
+ Class class_ = parent.target;
+ if (typeParameters.isEmpty) {
+ result.returnType = class_.thisType;
+ } else {
+ // Factory constructors get their own copy of type parameters, so we
+ // have to substitute.
+ result.returnType = Substitution
+ .fromPairs(
+ class_.typeParameters,
+ result.typeParameters
+ .map((p) => new TypeParameterType(p))
+ .toList())
+ .substituteType(class_.thisType);
+ }
+ }
if (typeParameters.isNotEmpty) {
Map<TypeParameter, DartType> substitution;
DartType removeTypeVariables(DartType type) {

Powered by Google App Engine
This is Rietveld 408576698