Skip to content

[SR-12430] self in Property Wrapper Using Enclosing Self Escapes Before Initialization Completed #54869

@swift-ci

Description

@swift-ci
Previous ID SR-12430
Radar None
Original Reporter briantkelley (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

macOS 10.15.4/Xcode 10.4

Also reproduces from trunk build at 3b3eade

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

md5: b9f06e7a94b959281ac36fd796a2e6c3

duplicates:

Issue Description:

In the attached sample code, self can be used to access uninitialized memory.

init(value: String) {
    self.value = value
}

@Notifying({ (p: Publisher, l: Listener) in l.propertyChanged(p) })
var value: String = ""

Where @Notifying is a property wrapper that uses the static subscript to access the enclosing self.

As a work around, the user can explicitly insert super.init():

init(value: String) {
    super.init()
    self.value = value
}

The Swift compiler should diagnose this scenario and emit an error diagnostic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfproperty wrappersFeature: property wrappers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions