Skip to content

Commit 6028ff1

Browse files
committed
Only declarations that are members of a type or extension can have member attributes
The last step in breaking the cycle through visible declaration lookup, e.g., with invalid code. Prior to this, we would get a false cyclic reference through the parameters of a function when they try to find property wrappers on the parameters.
1 parent 3249f4c commit 6028ff1

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ ArrayRef<unsigned> ExpandMemberAttributeMacros::evaluate(Evaluator &evaluator,
474474
return { };
475475

476476
auto *parentDecl = decl->getDeclContext()->getAsDecl();
477-
if (!parentDecl)
477+
if (!parentDecl || !isa<IterableDeclContext>(parentDecl))
478478
return { };
479479

480480
if (isa<PatternBindingDecl>(decl))

test/Macros/macro_expand_peers.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ struct S2 {
145145
}
146146

147147
#if TEST_DIAGNOSTICS
148-
// FIXME: Causes reference cycles
149-
// should have error {{cannot find 'nonexistent' in scope}}
150-
// @addCompletionHandlerArbitrarily(nonexistent)
148+
// expected-error@+1 {{cannot find 'nonexistent' in scope}}
149+
@addCompletionHandlerArbitrarily(nonexistent)
151150
func h(a: Int, for b: String, _ value: Double) async -> String {
152151
return b
153152
}

0 commit comments

Comments
 (0)