swiftlang / swift

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

[SR-11952] Property wrapper value can't be used in String(format:_:) #54372

Open jeremyabannister opened 4 years ago

jeremyabannister commented 4 years ago
Previous ID SR-11952
Radar rdar://problem/58435671
Original Reporter @jeremyabannister
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: aa10b179f2073347c9981bb284e6f896

Issue Description:

This does not compile:

@propertyWrapper
struct Wrap <Value> {
    private var storage: Value

    var wrappedValue: Value {
        get { storage }
        set { storage = newValue }
    }

    init (wrappedValue: Value) {
        self.storage = wrappedValue
    }
}

struct Foo {

    @Wrap
    private var bar: Int = 0

    var baz: String {
        String(format: "%02d", bar)
    }
}

But this does:

@propertyWrapper
struct Wrap <Value> {
    private var storage: Value

    var wrappedValue: Value {
        get { storage }
        set { storage = newValue }
    }

    init (wrappedValue: Value) {
        self.storage = wrappedValue
    }
}

struct Foo {

    @Wrap
    private var bar: Int = 0

    var baz: String {
        String(format: "%02d", _bar.wrappedValue)
    }
}
beccadax commented 4 years ago

@swift-ci create

theblixguy commented 4 years ago

Works fine on master. Can you verify again using the latest development snapshot?