[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 <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Regis Crelier 2020-04-25 01:12:17 +00:00 committed by commit-bot@chromium.org
parent 78907e46db
commit c99da6857f
2 changed files with 3 additions and 2 deletions

View file

@ -54,6 +54,7 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFieldInitializer() {
body += Constant(
Instance::ZoneHandle(Z, constant_reader_.ReadConstantExpression()));
} else {
body += SetupCapturedParameters(parsed_function()->function());
body += BuildExpression(); // read initializer.
}
body += Return(TokenPosition::kNoSource);

View file

@ -2779,7 +2779,7 @@ class Function : public Object {
bool HasThisParameter() const {
return IsDynamicFunction(/*allow_abstract=*/true) ||
IsGenerativeConstructor();
IsGenerativeConstructor() || (IsFieldInitializer() && !is_static());
}
bool IsDynamicFunction(bool allow_abstract = false) const {
@ -3245,7 +3245,7 @@ class Function : public Object {
return kind() == RawFunction::kImplicitSetter;
}
// Returns true if this function represents an the initializer for a static or
// Returns true if this function represents an initializer for a static or
// instance field. The function returns the initial value and the caller is
// responsible for setting the field.
bool IsFieldInitializer() const {