dart-sdk/pkg/kernel/testcases/closures
Samir Jindel 454ab91576 Fix duplicate context creation when closures appear in initializers.
Summary:

Previously, when a function parameter was captured both in an initializer and in
the body of a constructor, we would create two contexts: one created in a local
initializer and used by other initializers, and another in the body of the
function. This is incorrect, as it means that changes to the parameter in the
initializer's closure won't be visible in the body.

Now, to work around this problem we re-use the context created for the
initializers in the body of the constructor by moving the body into a new
constructor, and redirecting the original constructor to that one, passing the
context as an additional argument. This dance is necessary because local
initializers aren't visible in the body of a constructor.

Test Plan:

A few of the existing closure conversion tests were changed or fixed by this
revision. We also modify the 'closure_in_initializer.dart' test to hit this case
directly.

R=dmitryas@google.com

Reviewers: dmitryas@google.com
Review-Url: https://codereview.chromium.org/2991853002 .
2017-08-03 11:33:40 +02:00
..
capture_closure.dart
capture_closure.dart.expect Update expectations for closure conversion tests 2017-06-14 11:03:46 +02:00
capture_closure_parameter.dart Run dartfmt on kernel package 2017-03-17 08:21:52 -07:00
capture_closure_parameter.dart.expect Update expectations for closure conversion tests 2017-06-14 11:03:46 +02:00
capture_this.dart
capture_this.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00
catch.dart
catch.dart.expect Add primitive to create closures and use it for closure conversion 2017-03-31 14:43:56 +02:00
closure_in_constructor.dart Support closures in initializers 2017-02-28 11:16:41 +01:00
closure_in_constructor.dart.expect Fix duplicate context creation when closures appear in initializers. 2017-08-03 11:33:40 +02:00
closure_in_initializer.dart Fix duplicate context creation when closures appear in initializers. 2017-08-03 11:33:40 +02:00
closure_in_initializer.dart.expect Fix duplicate context creation when closures appear in initializers. 2017-08-03 11:33:40 +02:00
closure_in_initializer_closure.dart Run dartfmt on kernel package 2017-03-17 08:21:52 -07:00
closure_in_initializer_closure.dart.expect Fix duplicate context creation when closures appear in initializers. 2017-08-03 11:33:40 +02:00
closures.dart
closures.dart.expect Switch to Fasta in "golden" tests of closure conversion 2017-04-07 14:21:04 +02:00
contexts_in_field_initializers.dart Remove unnecessary contexts in closure conversion 2017-06-16 11:01:10 +02:00
contexts_in_field_initializers.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00
contexts_in_super_initializers.dart Remove unnecessary contexts in closure conversion 2017-06-16 11:01:10 +02:00
contexts_in_super_initializers.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00
field.dart
field.dart.expect Revert "Revert "Preserve type variables in closure conversion."" 2017-07-26 13:27:35 +02:00
for_in_closure.dart
for_in_closure.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00
for_loop.dart
for_loop.dart.expect Add primitive to create closures and use it for closure conversion 2017-03-31 14:43:56 +02:00
for_variable_capture_test.dart Run dartfmt on kernel package 2017-03-17 08:21:52 -07:00
for_variable_capture_test.dart.expect Add primitive to create closures and use it for closure conversion 2017-03-31 14:43:56 +02:00
instance_tear_off.dart
instance_tear_off.dart.expect Revert "Revert "Preserve type variables in closure conversion."" 2017-07-26 13:27:35 +02:00
named_closure.dart
named_closure.dart.expect Update expectations for closure conversion tests 2017-06-14 11:03:46 +02:00
non_void_context.dart
non_void_context.dart.expect Switch to Fasta in "golden" tests of closure conversion 2017-04-07 14:21:04 +02:00
README.md
static_tear_off.dart
static_tear_off.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00
uncaptured_for_in_loop.dart
uncaptured_for_in_loop.dart.expect Add support for converted closures with explicit contexts to VM 2017-07-21 11:45:15 +02:00

Running tests

export DART_AOT_SDK=.../xcodebuild/DerivedSources/DebugX64/patched_sdk
dart -c --packages=.packages package:testing/src/run_tests.dart test/closures/testing.json