[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>
This commit is contained in:
Dmitry Stefantsov
2019-11-08 10:24:36 +00:00
committed by commit-bot@chromium.org
parent ee2efe8e58
commit e4a60912a7
2 changed files with 13 additions and 2 deletions
@@ -2101,6 +2101,11 @@ class BinaryBuilder {
Supertype readSupertype() {
InterfaceType type = readDartType();
assert(
type.nullability == _currentLibrary.nonNullable,
"In serialized form supertypes should have Nullability.legacy if they "
"are in a library that is opted out of the NNBD feature. If they are "
"in an opted-in library, they should have Nullability.nonNullable.");
return new Supertype.byReference(type.className, type.typeArguments);
}
+8 -2
View File
@@ -54,6 +54,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
Set<CanonicalName> _knownCanonicalNameNonRootTops = new Set<CanonicalName>();
Set<CanonicalName> _reindexedCanonicalNames = new Set<CanonicalName>();
Library _currentLibrary;
/// Create a printer that writes to the given [sink].
///
/// The BinaryPrinter will use its own buffer, so the [sink] does not need
@@ -930,6 +932,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
@override
void visitLibrary(Library node) {
_currentLibrary = node;
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
insideExternalLibrary = node.isExternal;
libraryOffsets.add(getBufferOffset());
@@ -992,6 +996,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
writeUInt32(offset);
}
writeUInt32(procedureOffsets.length - 1);
_currentLibrary = null;
}
void writeLibraryDependencies(Library library) {
@@ -2068,11 +2074,11 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
// requires the nullability byte.
if (node.typeArguments.isEmpty) {
writeByte(Tag.SimpleInterfaceType);
writeByte(Nullability.nonNullable.index);
writeByte(_currentLibrary.nonNullable.index);
writeNonNullReference(node.className);
} else {
writeByte(Tag.InterfaceType);
writeByte(Nullability.nonNullable.index);
writeByte(_currentLibrary.nonNullable.index);
writeNonNullReference(node.className);
writeNodeList(node.typeArguments);
}