Skip to content

Commit c99da68

Browse files
creliercommit-bot@chromium.org
authored andcommitted
[VM/nnbd] Field initializers may allocate a context storing 'this' when needed.
This fixes these co19 tests in strong mode: LanguageFeatures/nnbd/late_A05_t01 LanguageFeatures/nnbd/late_A05_t02 Change-Id: I90e9f91eec120d82992e835f79396c2a7770fcbc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144814 Commit-Queue: Régis Crelier <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 78907e4 commit c99da68

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFieldInitializer() {
5454
body += Constant(
5555
Instance::ZoneHandle(Z, constant_reader_.ReadConstantExpression()));
5656
} else {
57+
body += SetupCapturedParameters(parsed_function()->function());
5758
body += BuildExpression(); // read initializer.
5859
}
5960
body += Return(TokenPosition::kNoSource);

runtime/vm/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,7 +2779,7 @@ class Function : public Object {
27792779

27802780
bool HasThisParameter() const {
27812781
return IsDynamicFunction(/*allow_abstract=*/true) ||
2782-
IsGenerativeConstructor();
2782+
IsGenerativeConstructor() || (IsFieldInitializer() && !is_static());
27832783
}
27842784

27852785
bool IsDynamicFunction(bool allow_abstract = false) const {
@@ -3245,7 +3245,7 @@ class Function : public Object {
32453245
return kind() == RawFunction::kImplicitSetter;
32463246
}
32473247

3248-
// Returns true if this function represents an the initializer for a static or
3248+
// Returns true if this function represents an initializer for a static or
32493249
// instance field. The function returns the initial value and the caller is
32503250
// responsible for setting the field.
32513251
bool IsFieldInitializer() const {

0 commit comments

Comments
 (0)