Skip to content

Commit 6d038c8

Browse files
committed
[Serialization] Skip deserializing invalid attributes if allowing errors
Most invalid attributes are skipped from serialization entirely, but custom attributes don't have their invalid bit set - the particular custom attribute (eg. a property wrapper) is requested when needed and skipped if invalid. Those checks can't set the invalid bit since the attribute could be a different custom attribute (eg. a result builder).
1 parent c490f92 commit 6d038c8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,6 +4505,9 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
45054505
skipAttr = true;
45064506
} else
45074507
return deserialized.takeError();
4508+
} else if (!deserialized.get() && MF.allowCompilerErrors()) {
4509+
// Serialized an invalid attribute, just skip it when allowing errors
4510+
skipAttr = true;
45084511
} else {
45094512
auto *TE = TypeExpr::createImplicit(deserialized.get(), ctx);
45104513
auto custom = CustomAttr::create(ctx, SourceLoc(), TE, isImplicit);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/errors.swiftmodule -experimental-allow-module-with-compiler-errors %s
4+
5+
// Property wrappers are invalid on top level code, check allowing errors
6+
// does not crash
7+
8+
@propertyWrapper
9+
public struct Wrapper<T> {
10+
public var wrappedValue: T
11+
public init() {}
12+
}
13+
@Wrapper
14+
public var topLevelVar: Int = 10

0 commit comments

Comments
 (0)