@@ -8353,6 +8353,7 @@ void ClangImporter::Implementation::importAttributes(
8353
8353
// Scan through Clang attributes and map them onto Swift
8354
8354
// equivalents.
8355
8355
PatternBindingInitializer *initContext = nullptr ;
8356
+ Optional<const clang::SwiftAttrAttr *> SeenMainActorAttr;
8356
8357
bool AnyUnavailable = MappedDecl->getAttrs ().isUnavailable (C);
8357
8358
for (clang::NamedDecl::attr_iterator AI = ClangDecl->attr_begin (),
8358
8359
AE = ClangDecl->attr_end (); AI != AE; ++AI) {
@@ -8496,15 +8497,32 @@ void ClangImporter::Implementation::importAttributes(
8496
8497
// __attribute__((swift_attr("attribute")))
8497
8498
//
8498
8499
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(*AI)) {
8499
- // FIXME: Hard-core @MainActor and @UIActor, because we don't have a
8500
+ // FIXME: Hard-code @MainActor and @UIActor, because we don't have a
8500
8501
// point at which to do name lookup for imported entities.
8501
8502
if (auto isMainActor = isMainActorAttr (SwiftContext, swiftAttr)) {
8502
8503
bool isUnsafe = *isMainActor;
8504
+
8505
+ if (SeenMainActorAttr) {
8506
+ // Cannot add main actor annotation twice. We'll keep the first
8507
+ // one and raise a warning about the duplicate.
8508
+ auto &clangSrcMgr = getClangASTContext ().getSourceManager ();
8509
+ ClangSourceBufferImporter &bufferImporter =
8510
+ getBufferImporterForDiagnostics ();
8511
+ SourceLoc attrLoc = bufferImporter.resolveSourceLocation (
8512
+ clangSrcMgr, swiftAttr->getLocation ());
8513
+
8514
+ diagnose (attrLoc, diag::import_multiple_mainactor_attr,
8515
+ swiftAttr->getAttribute (),
8516
+ SeenMainActorAttr.getValue ()->getAttribute ());
8517
+ continue ;
8518
+ }
8519
+
8503
8520
if (Type mainActorType = SwiftContext.getMainActorType ()) {
8504
8521
auto typeExpr = TypeExpr::createImplicit (mainActorType, SwiftContext);
8505
8522
auto attr = CustomAttr::create (SwiftContext, SourceLoc (), typeExpr);
8506
8523
attr->setArgIsUnsafe (isUnsafe);
8507
8524
MappedDecl->getAttrs ().add (attr);
8525
+ SeenMainActorAttr = swiftAttr;
8508
8526
}
8509
8527
8510
8528
continue ;
0 commit comments