Skip to content

Commit 3771ddd

Browse files
creliercommit-bot@chromium.org
authored andcommitted
[VM/nnbd] Force the DeclarationType of a class to have legacy nullability.
This is a workaround to avoid caching a non-legacy type (possibly provided by the CFE) as the canonical type of a non-generic class and later returned as the runtime type of an instance of this class. Hopefully fixes https://buganizer.corp.google.com/issues/144304690 Change-Id: Iaea364b9b743b05bde600f0aa784d5a8105728d7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124920 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Régis Crelier <regis@google.com>
1 parent 024a4b2 commit 3771ddd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

runtime/vm/object.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,11 +4351,16 @@ RawType* Class::DeclarationType(Nullability nullability) const {
43514351
if (!type.IsNull()) {
43524352
return type.ToNullability(nullability, Heap::kOld);
43534353
}
4354+
// TODO(regis): We should pass nullabiity to Type::New to avoid having to
4355+
// clone the type to the desired nullability. This however causes issues with
4356+
// the runtimeType intrinsic grabbing DeclarationType without checking its
4357+
// nullability. Indeed, when the CFE provides a non-nullable version of the
4358+
// type first, this non-nullable version gets cached as the declaration type.
43544359
type = Type::New(*this, TypeArguments::Handle(type_parameters()), token_pos(),
4355-
nullability);
4360+
Nullability::kLegacy);
43564361
type ^= ClassFinalizer::FinalizeType(*this, type);
43574362
set_declaration_type(type);
4358-
return type.raw();
4363+
return type.ToNullability(nullability, Heap::kOld);
43594364
}
43604365

43614366
void Class::set_allocation_stub(const Code& value) const {

0 commit comments

Comments
 (0)