From e4a60912a72a1ffdfc6f7d2d46c0a28fa5915495 Mon Sep 17 00:00:00 2001 From: Dmitry Stefantsov Date: Fri, 8 Nov 2019 10:24:36 +0000 Subject: [PATCH] [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 Commit-Queue: Dmitry Stefantsov --- pkg/kernel/lib/binary/ast_from_binary.dart | 5 +++++ pkg/kernel/lib/binary/ast_to_binary.dart | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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); }