Skip to content

Commit 8b4083a

Browse files
authored
Merge pull request #24346 from DougGregor/property-delegates-static
[Property delegates] Sure synthesized PatternBindingDecl static when needed
2 parents 10087eb + e7ef638 commit 8b4083a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ static VarDecl *synthesizePropertyDelegateStorageDelegateProperty(
14931493
ctx, property->getCorrectStaticSpelling(), pbdPattern,
14941494
/*init*/nullptr, dc, SourceLoc());
14951495
addMemberToContextIfNeeded(pbd, dc, var);
1496+
pbd->setStatic(var->isStatic());
14961497

14971498
// Determine the access level for the property.
14981499
AccessLevel access =
@@ -1575,6 +1576,7 @@ PropertyDelegateBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
15751576
ctx, backingVar->getCorrectStaticSpelling(), pbdPattern,
15761577
/*init*/nullptr, dc, SourceLoc());
15771578
addMemberToContextIfNeeded(pbd, dc, var);
1579+
pbd->setStatic(var->isStatic());
15781580

15791581
// Take the initializer from the original property.
15801582
auto parentPBD = var->getParentPatternBinding();

test/SILGen/property_delegates.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func forceHasMemberwiseInit() {
4040
_ = HasMemberwiseInit<Int>()
4141
}
4242

43+
// CHECK: sil_global hidden @$s18property_delegates9UseStaticV13$staticWibbleAA4LazyOySaySiGGvpZ : $Lazy<Array<Int>>
44+
4345
// HasMemberwiseInit.x.setter
4446
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s18property_delegates17HasMemberwiseInitV1xSbvs : $@convention(method) <T where T : DefaultInit> (Bool, @inout HasMemberwiseInit<T>) -> () {
4547
// CHECK: bb0(%0 : $Bool, %1 : $*HasMemberwiseInit<T>):
@@ -250,3 +252,10 @@ func triggerUseLazy() {
250252
_ = UseLazy(bar: 17)
251253
_ = UseLazy<Int>(wibble: [1, 2, 3])
252254
}
255+
256+
struct UseStatic {
257+
// CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvgZ
258+
// CHECK: sil hidden [global_init] [ossa] @$s18property_delegates9UseStaticV13$staticWibbleAA4LazyOySaySiGGvau
259+
// CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvsZ
260+
@Lazy static var staticWibble = [1, 2, 3]
261+
}

0 commit comments

Comments
 (0)