swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.06k stars 10.33k forks source link

[SR-12341] @propertyWrapper wrong behaviour #54775

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12341
Radar rdar://problem/60832285
Original Reporter Nostromo (JIRA User)
Type Bug
Environment Xcode: Version 11.3.1 (11C504) Swift: Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: cbb8599608eb9f716cf415a3616fff97

is duplicated by:

Issue Description:

For some reason the following code produces:

SomeSubClass init
subWillSet -  105553175052640 123 321
SomeSuperClass init

It seems that the @propertyWrapper can at some point access an uninitialized memory area.

@propertyWrapper
struct SomeWrapper {

    private var someValue: Int
    var wrappedValue: Int {
        get { someValue }
        set { someValue = newValue }
    }

    init(wrappedValue: Int) {
        someValue = wrappedValue
    }

}

class SomeSuperClass {

    @SomeWrapper var superProperty: Int

    init() {
        print("SomeSuperClass init")
        superProperty = 1
    }

}

final class SomeSubClass: SomeSuperClass {

    @SomeWrapper var subProperty: Int = 123 {
        willSet {
            print("subWillSet - ", superProperty, subProperty, newValue)
        }
    }

    override init() {
        print("SomeSubClass init")
        subProperty = 321
        super.init()
    }

}

let testObject = SomeSubClass()
beccadax commented 4 years ago

@swift-ci create