Skip to content

Commit 4faabc9

Browse files
authored
Merge pull request #77417 from hamishknight/duplicate-macro
[CS] Filter out invalid macros from overload set
2 parents b345418 + 4e7a119 commit 4faabc9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,6 +3997,10 @@ namespace {
39973997
auto results = namelookup::lookupMacros(CurDC, DeclNameRef(moduleName),
39983998
DeclNameRef(macroName), roles);
39993999
for (const auto &result : results) {
4000+
// Ignore invalid results. This matches the OverloadedDeclRefExpr
4001+
// logic.
4002+
if (result->isInvalid())
4003+
continue;
40004004
OverloadChoice choice = OverloadChoice(Type(), result, functionRefKind);
40014005
choices.push_back(choice);
40024006
}

test/Constraints/issue-77393.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/swiftlang/swift/issues/77393
4+
// Make sure we don't crash.
5+
6+
@freestanding(expression)
7+
macro someMacro() = #externalMacro(module: "", type: "")
8+
// expected-warning@-1 {{external macro implementation type '.' could not be found for macro 'someMacro()'; plugin for module '' not found}}
9+
// expected-note@-2 {{'someMacro()' previously declared here}}
10+
// expected-note@-3 {{'someMacro()' declared here}}
11+
12+
@freestanding(expression)
13+
macro someMacro() = #externalMacro(module: "", type: "")
14+
// expected-error@-1 {{invalid redeclaration of 'someMacro()'}}
15+
// expected-warning@-2 {{external macro implementation type '.' could not be found for macro 'someMacro()'; plugin for module '' not found}}
16+
17+
#someMacro()
18+
// expected-error@-1 {{external macro implementation type '.' could not be found for macro 'someMacro()'; plugin for module '' not found}}
19+
20+
macro invalidMacro()
21+
// expected-error@-1 {{macro 'invalidMacro()' requires a definition}}
22+
// expected-error@-2 {{macro 'invalidMacro()' must declare its applicable roles via '@freestanding' or @attached'}}
23+
24+
#invalidMacro() // expected-error {{no macro named 'invalidMacro'}}

0 commit comments

Comments
 (0)