Skip to content

Commit 117d453

Browse files
committed
[Sema] Avoid member attribute cycle in ResolveMacroRequest
If we have a custom attribute on a type that does a qualified lookup into the same type, we need to be able to expand member attribute macros for that type. As such, the check to see if we already have a nominal for the attribute would hit a cycle. Limit this check such that it only applies to local vars, which is the only case where it actually matters. rdar://163961797
1 parent 9981dc8 commit 117d453

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,8 +2242,12 @@ ResolveMacroRequest::evaluate(Evaluator &evaluator,
22422242
// So bail out to prevent diagnostics from the contraint system.
22432243
if (auto *attr = macroRef.getAttr()) {
22442244
// If we already resolved this CustomAttr to a nominal, this isn't for a
2245-
// macro.
2246-
if (attr->getNominalDecl())
2245+
// macro. This can only currently be the case for property wrappers, so
2246+
// limit the check here to avoid request cycles for member attribute macros
2247+
// in cases where the attribute refers to a nested type in the type it's
2248+
// attached to, since the qualified lookup there needs to expand member
2249+
// attributes.
2250+
if (attr->shouldPreferPropertyWrapperOverMacro() && attr->getNominalDecl())
22472251
return ConcreteDeclRef();
22482252

22492253
auto foundMacros = namelookup::lookupMacros(dc, macroRef.getModuleName(),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// Make sure we don't end up with a request cycle here, since looking up 'S.Actor'
4+
// requires expanding member attribute macros for 'S'.
5+
@S.Actor
6+
struct S {
7+
@globalActor actor Actor: GlobalActor {
8+
public static let shared = S.Actor()
9+
}
10+
}

0 commit comments

Comments
 (0)