Skip to content
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

[SR-13495] Property Wrappers May Leak Resources in Initializers #55937

Closed
swift-ci opened this issue Sep 4, 2020 · 4 comments
Closed

[SR-13495] Property Wrappers May Leak Resources in Initializers #55937

swift-ci opened this issue Sep 4, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 4, 2020

Previous ID SR-13495
Radar rdar://problem/68314811
Original Reporter briantkelley (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS Big Sur Beta 6
Xcode 12.0 Beta 6
Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
x86_64-apple-darwin20.1.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee briantkelley (JIRA)
Priority Medium

md5: 1aad3a12f6edcdb532443a87ca442d59

Issue Description:

In the attached sample program, an assignment is made through a property wrapper before and after the call to super.init(). The compiler leaks the resources assigned to the property at its definition.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Sep 4, 2020

Comment by Brian T. Kelley (JIRA)

Also filed FB8621431.

@hborla
Copy link
Member

hborla commented Sep 10, 2020

Thank you for investigating this and filing the issue!

The problem is that we're not re-writing assign_by_wrapper to re-assignment of the backing property wrapper in the case where it has already been initialized. Regardless of property observers, we can't call the getter or setter of the wrapped value before all of self is initialized because of enclosing self property wrappers, and it would be really unfortunate to not allow this kind of code for such property wrappers:

class C {
  @Published var value = 10
  var str: String

  init(value: Int, str: String) {
    self.value = value
    self.str = str
  } 
}

@hborla
Copy link
Member

hborla commented Sep 12, 2020

#33923

@hborla
Copy link
Member

hborla commented Dec 20, 2020

Just realized I forgot to resolve this. Could you please verify in the latest Xcode or Swift 5.3.2? Thank you!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants