Skip to content

Commit 2b400a1

Browse files
authored
Merge pull request #64807 from DougGregor/innermost-macro-context-5.9
2 parents 3f60a1d + 62fabb6 commit 2b400a1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ DeclContext *Decl::getInnermostDeclContext() const {
574574
return const_cast<ExtensionDecl*>(ext);
575575
if (auto topLevel = dyn_cast<TopLevelCodeDecl>(this))
576576
return const_cast<TopLevelCodeDecl*>(topLevel);
577+
if (auto macro = dyn_cast<MacroDecl>(this))
578+
return const_cast<MacroDecl*>(macro);
577579

578580
return getDeclContext();
579581
}

test/Macros/macros_diagnostics.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ func test() {
169169
let _: [MacroOrType.Nested] = []
170170
_ = [MacroOrType.Nested]()
171171
}
172+
173+
// Make sure we have the right declaration context for type-checking the result
174+
// types of macros. At one point, we would reject the following macro.
175+
protocol MyProto {
176+
}
177+
struct MyStruct<T: MyProto> {
178+
}
179+
180+
@freestanding(expression) macro myMacro<T : MyProto>(_ value: MyStruct<T>) -> MyStruct<T> = #externalMacro(module: "A", type: "B")
181+
// expected-warning@-1{{external macro implementation type}}

0 commit comments

Comments
 (0)