Skip to content

Commit a359816

Browse files
committed
[Macros] Ban extension macros on local nested types
Make sure we check whether we are in any local parent context.
1 parent aaeb38d commit a359816

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ std::optional<unsigned> swift::expandExtensions(CustomAttr *attr,
20932093
MacroDecl *macro,
20942094
MacroRole role,
20952095
NominalTypeDecl *nominal) {
2096-
if (nominal->getDeclContext()->isLocalContext()) {
2096+
if (nominal->getLocalContext()) {
20972097
nominal->diagnose(diag::local_extension_macro);
20982098
return std::nullopt;
20992099
}

test/Macros/macro_expand_extensions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func testLocal() {
115115
@DelegatedConformance
116116
struct Local<Element> {}
117117
// expected-error@-1{{local type cannot have attached extension macro}}
118+
119+
struct S {
120+
@DelegatedConformance
121+
struct Local<Element> {}
122+
// expected-error@-1{{local type cannot have attached extension macro}}
123+
}
118124
}
119125

120126
@DelegatedConformance

0 commit comments

Comments
 (0)