Skip to content

Commit 51a5fc9

Browse files
committed
Test shadow not qualified macro
1 parent 0cb1246 commit 51a5fc9

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,11 +1630,6 @@ SmallVector<MacroDecl *, 1> namelookup::lookupMacros(DeclContext *dc,
16301630
auto moduleScopeDC = dc->getModuleScopeContext();
16311631
ASTContext &ctx = moduleScopeDC->getASTContext();
16321632

1633-
// When performing lookup for freestanding macro roles, only consider
1634-
// macro names, ignoring types.
1635-
bool onlyMacros = static_cast<bool>(roles & getFreestandingMacroRoles()) &&
1636-
!(roles - getFreestandingMacroRoles());
1637-
16381633
auto addChoiceIfApplicable = [&](ValueDecl *decl) {
16391634
if (auto macro = dyn_cast<MacroDecl>(decl)) {
16401635
auto candidateRoles = macro->getMacroRoles();
@@ -1658,12 +1653,9 @@ SmallVector<MacroDecl *, 1> namelookup::lookupMacros(DeclContext *dc,
16581653
if (!moduleDecl)
16591654
return {};
16601655

1661-
auto options = NL_ExcludeMacroExpansions;
1662-
if (onlyMacros)
1663-
options |= NL_OnlyMacros;
1664-
16651656
ModuleQualifiedLookupRequest req{moduleScopeDC, moduleDecl, macroName,
1666-
SourceLoc(), options};
1657+
SourceLoc(),
1658+
NL_ExcludeMacroExpansions | NL_OnlyMacros};
16671659
auto lookup = evaluateOrDefault(ctx.evaluator, req, {});
16681660
for (auto *found : lookup)
16691661
addChoiceIfApplicable(found);
@@ -1675,10 +1667,8 @@ SmallVector<MacroDecl *, 1> namelookup::lookupMacros(DeclContext *dc,
16751667
// the source location here doesn't matter.
16761668
UnqualifiedLookupDescriptor descriptor{
16771669
macroName, moduleScopeDC, SourceLoc(),
1678-
UnqualifiedLookupFlags::ExcludeMacroExpansions};
1679-
1680-
if (onlyMacros)
1681-
descriptor.Options |= UnqualifiedLookupFlags::MacroLookup;
1670+
UnqualifiedLookupFlags::ExcludeMacroExpansions |
1671+
UnqualifiedLookupFlags::MacroLookup};
16821672

16831673
auto lookup = evaluateOrDefault(ctx.evaluator,
16841674
UnqualifiedLookupRequest{descriptor}, {});
@@ -1726,9 +1716,9 @@ void namelookup::forEachPotentialResolvedMacro(
17261716
) {
17271717
ASTContext &ctx = moduleScopeCtx->getASTContext();
17281718
UnqualifiedLookupDescriptor lookupDesc{
1729-
macroName, moduleScopeCtx, SourceLoc(),
1730-
UnqualifiedLookupFlags::ExcludeMacroExpansions
1731-
};
1719+
macroName, moduleScopeCtx, SourceLoc(),
1720+
UnqualifiedLookupFlags::ExcludeMacroExpansions |
1721+
UnqualifiedLookupFlags::MacroLookup};
17321722

17331723
auto lookup = evaluateOrDefault(
17341724
ctx.evaluator, UnqualifiedLookupRequest{lookupDesc}, {});

test/Macros/macro_shadowing.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ func testStringify(a: Int, b: Int) {
2020
_ = #stringify(a + b)
2121
}
2222

23+
@propertyWrapper
24+
struct declareVarValuePeer {
25+
var wrappedValue: Int
26+
}
27+
28+
struct TestShadowUnqualified {
29+
@declareVarValuePeer
30+
var shouldFindMacro: Int = 2
31+
}
32+
33+
_ = TestShadowUnqualified().value
34+
2335
enum macro_library {
2436
@propertyWrapper
2537
struct declareVarValuePeerShadowed {

0 commit comments

Comments
 (0)