Open swift-ci opened 4 years ago
Works fine on 5.2. Could you please verify using the latest 5.2 development snapshot?
Comment by Wayne2046 (JIRA)
The same error on 5.2-dev.
Can you try a trunk (master) snapshot?
Comment by Owen Voorhees (JIRA)
I can reproduce this with a build of master from Jan. 7 (667fc05fe0bc9f65173c77afe35ab6d36abcd689). I don't think anything that could have fixed this has gone in since then, I could be mistaken though.
Hmm, I am on Swift version 5.2-dev (Swift 51b8914211) [Target: x86_64-apple-darwin19.0.0] and it works fine, but I haven't pulled from master since a week or two, so perhaps something regressed. I'll pull in from master again and see what's going on.
Okay, my bad. I was not trying the @SmallNumber(maximum: 9) var width: Int = 2
example that you provided at the bottom. I can confirm this reproduces on master as well.
So, I don't think this is a bug, because wrappedValue
must be the first argument of the initializer. The compiler synthesises an implicit call to the initializer with wrappedValue
as first argument (see this). Perhaps we should emit a diagnostic for this.
The obvious fix is to rearrange the arguments of your initializer (or offer two with different order).
@swift-ci create
Attachment: Download
Environment
Xcode 11.3 (11C29) Playground Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15) Target: x86_64-apple-darwin18.7.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, PropertyWrappers | |Assignee | None | |Priority | Medium | md5: 291e78349afba012c209e9db4140d930Issue Description:
The Swift language reference does not mention that 'wrappedValue' must be the first parameter of initializers of Property Wrapper. In the above snippet, although the 'wrappedValue' is not the first parameter of the initializer, the code output the desired result as following:
But if we use mixed form of syntactic sugar for initialization of Property Wrapper, then errors occurs.