Skip to content

[Property delegates] Sure synthesized PatternBindingDecl static when needed #24346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ static VarDecl *synthesizePropertyDelegateStorageDelegateProperty(
ctx, property->getCorrectStaticSpelling(), pbdPattern,
/*init*/nullptr, dc, SourceLoc());
addMemberToContextIfNeeded(pbd, dc, var);
pbd->setStatic(var->isStatic());

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

// Take the initializer from the original property.
auto parentPBD = var->getParentPatternBinding();
Expand Down
9 changes: 9 additions & 0 deletions test/SILGen/property_delegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func forceHasMemberwiseInit() {
_ = HasMemberwiseInit<Int>()
}

// CHECK: sil_global hidden @$s18property_delegates9UseStaticV13$staticWibbleAA4LazyOySaySiGGvpZ : $Lazy<Array<Int>>

// HasMemberwiseInit.x.setter
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s18property_delegates17HasMemberwiseInitV1xSbvs : $@convention(method) <T where T : DefaultInit> (Bool, @inout HasMemberwiseInit<T>) -> () {
// CHECK: bb0(%0 : $Bool, %1 : $*HasMemberwiseInit<T>):
Expand Down Expand Up @@ -250,3 +252,10 @@ func triggerUseLazy() {
_ = UseLazy(bar: 17)
_ = UseLazy<Int>(wibble: [1, 2, 3])
}

struct UseStatic {
// CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvgZ
// CHECK: sil hidden [global_init] [ossa] @$s18property_delegates9UseStaticV13$staticWibbleAA4LazyOySaySiGGvau
// CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvsZ
@Lazy static var staticWibble = [1, 2, 3]
}