mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
[vm/nnbd] Mark static fields in opted-in libraries as late
According to the NNBD feature specification, "a toplevel or static variable with an initializer is evaluated as if it was marked late". This change actually marks all static fields in opted-in libraries as late, in order to make sure that the rest of the VM handles such fields uniformly as late. Without this change implicit getters for such fields were generated as late, but type propagation didn't treat these fields as nullable, so field initialization checks were removed if field has a non-nullable type. Change-Id: I95bc096fb1d304b112369428dbb29d346964383f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140767 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Régis Crelier <regis@google.com> Reviewed-by: Liam Appelbe <liama@google.com>
This commit is contained in:
parent
c6dd41bfb3
commit
8c4909aa8f
|
@ -632,7 +632,10 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
if (field.isExtensionMember) {
|
||||
flags |= FieldDeclaration.isExtensionMemberFlag;
|
||||
}
|
||||
if (field.isLate) {
|
||||
// In NNBD libraries, static fields act like late fields
|
||||
// regardless of whether they're marked late.
|
||||
if (field.isLate ||
|
||||
(field.isStatic && field.enclosingLibrary.isNonNullableByDefault)) {
|
||||
flags |= FieldDeclaration.isLateFlag;
|
||||
}
|
||||
int position = TreeNode.noOffset;
|
||||
|
|
|
@ -1221,7 +1221,9 @@ void KernelLoader::FinishTopLevelClassLoading(
|
|||
// Only instance fields could be covariant.
|
||||
ASSERT(!field_helper.IsCovariant() &&
|
||||
!field_helper.IsGenericCovariantImpl());
|
||||
const bool is_late = field_helper.IsLate();
|
||||
// In NNBD libraries, static fields act like late fields
|
||||
// regardless of whether they're marked late.
|
||||
const bool is_late = field_helper.IsLate() || library.is_nnbd();
|
||||
const bool is_extension_member = field_helper.IsExtensionMember();
|
||||
const Field& field = Field::Handle(
|
||||
Z, Field::NewTopLevel(name, is_final, field_helper.IsConst(), is_late,
|
||||
|
@ -1577,7 +1579,10 @@ void KernelLoader::FinishClassLoading(const Class& klass,
|
|||
// In the VM all const fields are implicitly final whereas in Kernel they
|
||||
// are not final because they are not explicitly declared that way.
|
||||
const bool is_final = field_helper.IsConst() || field_helper.IsFinal();
|
||||
const bool is_late = field_helper.IsLate();
|
||||
// In NNBD libraries, static fields act like late fields
|
||||
// regardless of whether they're marked late.
|
||||
const bool is_late = field_helper.IsLate() ||
|
||||
(field_helper.IsStatic() && library.is_nnbd());
|
||||
const bool is_extension_member = field_helper.IsExtensionMember();
|
||||
Field& field = Field::Handle(
|
||||
Z, Field::New(name, field_helper.IsStatic(), is_final,
|
||||
|
|
Loading…
Reference in a new issue