Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.kernel_procedure_builder; | 5 library fasta.kernel_procedure_builder; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
| 8 show | 8 show |
| 9 Arguments, | 9 Arguments, |
| 10 AsyncMarker, | 10 AsyncMarker, |
| 11 Class, | |
| 11 Constructor, | 12 Constructor, |
| 12 ConstructorInvocation, | 13 ConstructorInvocation, |
| 13 DartType, | 14 DartType, |
| 14 DynamicType, | 15 DynamicType, |
| 15 EmptyStatement, | 16 EmptyStatement, |
| 16 Expression, | 17 Expression, |
| 17 FunctionNode, | 18 FunctionNode, |
| 18 Initializer, | 19 Initializer, |
| 19 LocalInitializer, | 20 LocalInitializer, |
| 20 Member, | 21 Member, |
| 21 Name, | 22 Name, |
| 22 NamedExpression, | 23 NamedExpression, |
| 23 Procedure, | 24 Procedure, |
| 24 ProcedureKind, | 25 ProcedureKind, |
| 25 RedirectingInitializer, | 26 RedirectingInitializer, |
| 26 Statement, | 27 Statement, |
| 27 StaticInvocation, | 28 StaticInvocation, |
| 28 StringLiteral, | 29 StringLiteral, |
| 29 SuperInitializer, | 30 SuperInitializer, |
| 30 TypeParameter, | 31 TypeParameter, |
| 32 TypeParameterType, | |
| 31 VariableDeclaration, | 33 VariableDeclaration, |
| 32 VariableGet, | 34 VariableGet, |
| 33 VoidType, | 35 VoidType, |
| 34 setParents; | 36 setParents; |
| 35 | 37 |
| 36 import 'package:kernel/type_algebra.dart' show containsTypeVariable, substitute; | 38 import 'package:kernel/type_algebra.dart' |
| 39 show Substitution, containsTypeVariable, substitute; | |
| 37 | 40 |
| 38 import '../errors.dart' show internalError; | 41 import '../errors.dart' show internalError; |
| 39 | 42 |
| 40 import '../messages.dart' show warning; | 43 import '../messages.dart' show warning; |
| 41 | 44 |
| 42 import '../loader.dart' show Loader; | 45 import '../loader.dart' show Loader; |
| 43 | 46 |
| 44 import 'kernel_builder.dart' | 47 import 'kernel_builder.dart' |
| 45 show | 48 show |
| 46 Builder, | 49 Builder, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 if (formal.isRequired) { | 118 if (formal.isRequired) { |
| 116 result.requiredParameterCount++; | 119 result.requiredParameterCount++; |
| 117 } | 120 } |
| 118 } | 121 } |
| 119 } | 122 } |
| 120 if (returnType != null) { | 123 if (returnType != null) { |
| 121 result.returnType = returnType.build(library); | 124 result.returnType = returnType.build(library); |
| 122 } | 125 } |
| 123 if (!isConstructor && !isInstanceMember && parent is ClassBuilder) { | 126 if (!isConstructor && !isInstanceMember && parent is ClassBuilder) { |
| 124 List<TypeParameter> typeParameters = parent.target.typeParameters; | 127 List<TypeParameter> typeParameters = parent.target.typeParameters; |
| 128 if (kind == ProcedureKind.Factory) { | |
|
ahe
2017/06/01 09:10:08
This I have a different solution for.
| |
| 129 Class class_ = parent.target; | |
| 130 if (typeParameters.isEmpty) { | |
| 131 result.returnType = class_.thisType; | |
| 132 } else { | |
| 133 // Factory constructors get their own copy of type parameters, so we | |
| 134 // have to substitute. | |
| 135 result.returnType = Substitution | |
| 136 .fromPairs( | |
| 137 class_.typeParameters, | |
| 138 result.typeParameters | |
| 139 .map((p) => new TypeParameterType(p)) | |
| 140 .toList()) | |
| 141 .substituteType(class_.thisType); | |
| 142 } | |
| 143 } | |
| 125 if (typeParameters.isNotEmpty) { | 144 if (typeParameters.isNotEmpty) { |
| 126 Map<TypeParameter, DartType> substitution; | 145 Map<TypeParameter, DartType> substitution; |
| 127 DartType removeTypeVariables(DartType type) { | 146 DartType removeTypeVariables(DartType type) { |
| 128 if (substitution == null) { | 147 if (substitution == null) { |
| 129 substitution = <TypeParameter, DartType>{}; | 148 substitution = <TypeParameter, DartType>{}; |
| 130 for (TypeParameter parameter in typeParameters) { | 149 for (TypeParameter parameter in typeParameters) { |
| 131 substitution[parameter] = const DynamicType(); | 150 substitution[parameter] = const DynamicType(); |
| 132 } | 151 } |
| 133 } | 152 } |
| 134 warning(fileUri, charOffset, | 153 warning(fileUri, charOffset, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 381 } |
| 363 } | 382 } |
| 364 initializers.add(initializer..parent = constructor); | 383 initializers.add(initializer..parent = constructor); |
| 365 initializers.add(superInitializer); | 384 initializers.add(superInitializer); |
| 366 return; | 385 return; |
| 367 } | 386 } |
| 368 initializers.add(initializer); | 387 initializers.add(initializer); |
| 369 initializer.parent = constructor; | 388 initializer.parent = constructor; |
| 370 } | 389 } |
| 371 } | 390 } |
| OLD | NEW |