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

Unified Diff: pkg/kernel/lib/transformations/erasure.dart

Issue 2993993002: Implement erasure of local function declarations. (Closed)
Patch Set: Fix typo and merge with master. Created 3 years, 4 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/kernel/lib/ast.dart ('k') | pkg/kernel/test/erasure_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/transformations/erasure.dart
diff --git a/pkg/kernel/lib/transformations/erasure.dart b/pkg/kernel/lib/transformations/erasure.dart
index c2f572d2c7855188f5a5b059b87eb064ba933a1e..ee3695857cc54ed5a0ed0e3bf19b562b7fe4dbdd 100644
--- a/pkg/kernel/lib/transformations/erasure.dart
+++ b/pkg/kernel/lib/transformations/erasure.dart
@@ -51,6 +51,31 @@ class Erasure extends Transformer {
@override
visitDartType(DartType type) {
+ if (type is FunctionType && type.typeParameters.isNotEmpty) {
+ FunctionType function = type;
+ for (var parameter in function.typeParameters) {
+ // Note, normally, we would have to remove these substitutions again to
+ // avoid memory leaks. Unfortunately, that that's not compatible with
+ // how function types share their TypeParameter object with a
+ // FunctionNode.
+ substitution[parameter] = const DynamicType();
+ }
+ for (var parameter in function.typeParameters) {
+ if (!isObject(parameter.bound)) {
+ substitution[parameter] = substitute(parameter.bound, substitution);
+ }
+ }
+ // We need to delete the type parameters of the function type before
+ // calling [substitute], otherwise it creates a new environment with
+ // fresh type variables that shadow the ones we want to remove. Since a
+ // FunctionType is often assumed to be immutable, we return a copy.
+ type = new FunctionType(
+ function.positionalParameters, function.returnType,
+ namedParameters: function.namedParameters,
+ requiredParameterCount: function.requiredParameterCount,
+ positionalParameterNames: function.positionalParameterNames,
+ typedefReference: function.typedefReference);
+ }
type = substitute(type, substitution);
if (isInConstantContext) {
type = substitute(type, constantSubstitution);
« no previous file with comments | « pkg/kernel/lib/ast.dart ('k') | pkg/kernel/test/erasure_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698