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

Unified Diff: runtime/vm/parser.cc

Issue 2835363002: Properly handle implicit closure function when a generic function. (Closed)
Patch Set: Created 3 years, 8 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
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index ff7660abe09b490ebfaeafa548ca16887ad110ea..6371905dbf3df53434cb69fd6d43d239d9ae4ae9 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -1557,6 +1557,24 @@ SequenceNode* Parser::ParseImplicitClosure(const Function& func) {
OpenFunctionBlock(func);
+ if (FLAG_reify_generic_functions) {
+ // The parent function of an implicit closure is the original function, i.e.
+ // non-closurized. It is not an enclosing function in the usual sense of a
+ // parent function. Do not set parent_type_arguments() in parsed_function_.
+ ASSERT(func.IsGeneric() == func.HasGenericParent());
+
+ if (func.IsGeneric()) {
+ // Insert function type arguments variable to scope.
+ LocalVariable* function_type_arguments = new (Z) LocalVariable(
+ TokenPosition::kNoSource, TokenPosition::kNoSource,
+ Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
+ current_block_->scope->AddVariable(function_type_arguments);
+ ASSERT(FunctionLevel() == 0);
+ parsed_function_->set_function_type_arguments(function_type_arguments);
+ }
+ }
+
+ // TODO(regis): Pass the function type arguments if func is generic.
ParamList params;
params.AddFinalParameter(token_pos, &Symbols::ClosureParameter(),
&Object::dynamic_type());
@@ -3460,7 +3478,7 @@ SequenceNode* Parser::ParseFunc(const Function& func, bool check_semicolon) {
ASSERT(!func.IsGenerativeConstructor());
OpenFunctionBlock(func); // Build local scope for function.
- if (FLAG_reify_generic_functions && func.IsGeneric()) {
+ if (FLAG_reify_generic_functions) {
// Lookup function type arguments variable in parent function scope, if any.
if (func.HasGenericParent()) {
const String* variable_name = &Symbols::FunctionTypeArgumentsVar();
@@ -3470,14 +3488,23 @@ SequenceNode* Parser::ParseFunc(const Function& func, bool check_semicolon) {
// TODO(regis): It may be too early to capture parent_type_arguments here.
// In case it is never used, we could save capturing and concatenating.
current_block_->scope->CaptureVariable(parent_type_arguments);
- parsed_function_->set_parent_type_arguments(parent_type_arguments);
- }
- // Insert function type arguments variable to scope.
- LocalVariable* function_type_arguments = new (Z) LocalVariable(
- TokenPosition::kNoSource, TokenPosition::kNoSource,
- Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
- current_block_->scope->AddVariable(function_type_arguments);
- parsed_function_->set_function_type_arguments(function_type_arguments);
+ if (FunctionLevel() == 0) {
+ parsed_function_->set_parent_type_arguments(parent_type_arguments);
+ if (!func.IsGeneric() && parent_type_arguments->is_captured()) {
+ parsed_function_->set_function_type_arguments(parent_type_arguments);
+ }
+ }
+ }
+ if (func.IsGeneric()) {
+ // Insert function type arguments variable to scope.
+ LocalVariable* function_type_arguments = new (Z) LocalVariable(
+ TokenPosition::kNoSource, TokenPosition::kNoSource,
+ Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
+ current_block_->scope->AddVariable(function_type_arguments);
+ if (FunctionLevel() == 0) {
+ parsed_function_->set_function_type_arguments(function_type_arguments);
+ }
+ }
}
ParamList params;
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698