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-11477] Property Wrapper with initializer with default arguments can be used without parenthesis #53877

Closed
swift-ci opened this issue Sep 16, 2019 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11477
Radar None
Original Reporter MartialL (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Tested on:

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin18.7.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, PropertyWrappers
Assignee @theblixguy
Priority Medium

md5: bcbfc6c2401f99dce119ce97768cb959

Issue Description:

Let's take a simple useless property wrapper with two initializers: one without argument (implemented with a default value) and one with the argument

@propertyWrapper
struct Foo {
    let name: String

    init() {
        self.name = ""
    }

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

    var wrappedValue: Int {
        get { return 0 }
    }
}

struct TestFoo {
    @Foo var v1: Int
    @Foo() var v2: Int
    @Foo(name: "v3") var v3: Int

   init() { }
}

All three way to use the property wrapper is accepted by the compiler.

Now if we implement the same property wrapper but with one initializer using default parameter :

@propertyWrapper
struct Bar {
    let name: String

    init(name: String = "") {
        self.name = name
    }

    var wrappedValue: Int {
        get { return 0 }
    }
}

struct TestBar {
    @Bar var v1: Int
    @Bar() var v2: Int
    @Bar(name: "v3") var v3: Int

    init() {
        /* Compilation error
        error: return from initializer without initializing all stored properties
        note: 'self.v1' not initialized
         */
    }
}

We have a compilation error. The property wrapper without parenthesis doesn't match the initializer with default parameter.

Expected result :

Initializer with default parameter should match when using property wrapper without parenthesis.

@belkadan
Copy link
Contributor

@DougGregor, is this intentional? (Limiting the default-initialization of a property wrapper to init() rather than any initializer that can be called with no arguments.)

@theblixguy
Copy link
Collaborator

PR: #27253

@theblixguy
Copy link
Collaborator

Fixed on master. Please verify using the next available development snapshot!

@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 property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

3 participants