diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart index 197d6b38551..21780933def 100644 --- a/pkg/kernel/lib/binary/ast_from_binary.dart +++ b/pkg/kernel/lib/binary/ast_from_binary.dart @@ -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); } diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart index 382d3998bd6..141f1428eaa 100644 --- a/pkg/kernel/lib/binary/ast_to_binary.dart +++ b/pkg/kernel/lib/binary/ast_to_binary.dart @@ -54,6 +54,8 @@ class BinaryPrinter implements Visitor, BinarySink { Set _knownCanonicalNameNonRootTops = new Set(); Set _reindexedCanonicalNames = new Set(); + 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, 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, BinarySink { writeUInt32(offset); } writeUInt32(procedureOffsets.length - 1); + + _currentLibrary = null; } void writeLibraryDependencies(Library library) { @@ -2068,11 +2074,11 @@ class BinaryPrinter implements Visitor, 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); }