Skip to content

Commit e4a6091

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
authored andcommitted
[cfe] Use library's NNBD opt-in status while serializing supertypes
Change-Id: Id1ab5fd9a36b4aadb213febb0e1ae2eba968244d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124331 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
1 parent ee2efe8 commit e4a6091

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/kernel/lib/binary/ast_from_binary.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,11 @@ class BinaryBuilder {
21012101

21022102
Supertype readSupertype() {
21032103
InterfaceType type = readDartType();
2104+
assert(
2105+
type.nullability == _currentLibrary.nonNullable,
2106+
"In serialized form supertypes should have Nullability.legacy if they "
2107+
"are in a library that is opted out of the NNBD feature. If they are "
2108+
"in an opted-in library, they should have Nullability.nonNullable.");
21042109
return new Supertype.byReference(type.className, type.typeArguments);
21052110
}
21062111

pkg/kernel/lib/binary/ast_to_binary.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
5454
Set<CanonicalName> _knownCanonicalNameNonRootTops = new Set<CanonicalName>();
5555
Set<CanonicalName> _reindexedCanonicalNames = new Set<CanonicalName>();
5656

57+
Library _currentLibrary;
58+
5759
/// Create a printer that writes to the given [sink].
5860
///
5961
/// The BinaryPrinter will use its own buffer, so the [sink] does not need
@@ -930,6 +932,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
930932

931933
@override
932934
void visitLibrary(Library node) {
935+
_currentLibrary = node;
936+
933937
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
934938
insideExternalLibrary = node.isExternal;
935939
libraryOffsets.add(getBufferOffset());
@@ -992,6 +996,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
992996
writeUInt32(offset);
993997
}
994998
writeUInt32(procedureOffsets.length - 1);
999+
1000+
_currentLibrary = null;
9951001
}
9961002

9971003
void writeLibraryDependencies(Library library) {
@@ -2068,11 +2074,11 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
20682074
// requires the nullability byte.
20692075
if (node.typeArguments.isEmpty) {
20702076
writeByte(Tag.SimpleInterfaceType);
2071-
writeByte(Nullability.nonNullable.index);
2077+
writeByte(_currentLibrary.nonNullable.index);
20722078
writeNonNullReference(node.className);
20732079
} else {
20742080
writeByte(Tag.InterfaceType);
2075-
writeByte(Nullability.nonNullable.index);
2081+
writeByte(_currentLibrary.nonNullable.index);
20762082
writeNonNullReference(node.className);
20772083
writeNodeList(node.typeArguments);
20782084
}

0 commit comments

Comments
 (0)