Skip to content

Commit 1f6b3f6

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 4f6ab4b commit 1f6b3f6

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
@@ -458,7 +458,7 @@ ArrayRef<unsigned> ExpandMemberAttributeMacros::evaluate(Evaluator &evaluator,
458458
return { };
459459

460460
auto *parentDecl = decl->getDeclContext()->getAsDecl();
461-
if (!parentDecl)
461+
if (!parentDecl || !isa<IterableDeclContext>(parentDecl))
462462
return { };
463463

464464
if (isa<PatternBindingDecl>(decl))

test/Macros/macro_expand_peers.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ struct S2 {
149149
}
150150

151151
#if TEST_DIAGNOSTICS
152-
// FIXME: Causes reference cycles
153-
// should have error {{cannot find 'nonexistent' in scope}}
154-
// @addCompletionHandlerArbitrarily(nonexistent)
152+
// expected-error@+1 {{cannot find 'nonexistent' in scope}}
153+
@addCompletionHandlerArbitrarily(nonexistent)
155154
func h(a: Int, for b: String, _ value: Double) async -> String {
156155
return b
157156
}

0 commit comments

Comments
 (0)