Skip to content

Commit 15d7a21

Browse files
committed
[Macros] Diagnose availability of attached macros
(cherry picked from commit c3af8cb)
1 parent c80593c commit 15d7a21

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
528528

529529
DeclVisitor<AccessControlChecker>::visit(D);
530530
checkGlobalActorAccess(D);
531+
checkAttachedMacrosAccess(D);
531532
}
532533

533534
// Force all kinds to be handled at a lower level.
@@ -1260,6 +1261,18 @@ class AccessControlChecker : public AccessControlCheckerBase,
12601261
noteLimitingImport(MD->getASTContext(), minImportLimit, complainRepr);
12611262
}
12621263
}
1264+
1265+
void checkAttachedMacrosAccess(const Decl *D) {
1266+
for (auto customAttrC : D->getSemanticAttrs().getAttributes<CustomAttr>()) {
1267+
auto customAttr = const_cast<CustomAttr *>(customAttrC);
1268+
auto *macroDecl = D->getResolvedMacro(customAttr);
1269+
if (macroDecl) {
1270+
diagnoseDeclAvailability(
1271+
macroDecl, customAttr->getTypeRepr()->getSourceRange(), nullptr,
1272+
ExportContext::forDeclSignature(const_cast<Decl *>(D)), llvm::None);
1273+
}
1274+
}
1275+
}
12631276
};
12641277

12651278
class UsableFromInlineChecker : public AccessControlCheckerBase,

test/Macros/macro_expand_peers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,18 @@ func testStructWithPeers() {
231231
let x = SomeStructWithPeerProperties()
232232
print(x)
233233
}
234+
235+
236+
#if TEST_DIAGNOSTICS
237+
@available(*, deprecated, message: "This macro is deprecated.")
238+
@attached(peer, names: overloaded)
239+
macro deprecatedAddCompletionHandler() = #externalMacro(module: "MacroDefinition", type: "AddCompletionHandler")
240+
241+
242+
// expected-warning@+1{{'deprecatedAddCompletionHandler()' is deprecated: This macro is deprecated.}}
243+
@deprecatedAddCompletionHandler
244+
func fDeprecated(a: Int, for b: String, _ value: Double) async -> String {
245+
return b
246+
}
247+
248+
#endif

0 commit comments

Comments
 (0)