Skip to content

[SR-14133] Variable being used before being initialization #56513

@swift-ci

Description

@swift-ci
Previous ID SR-14133
Radar None
Original Reporter JaydenIrwin (JIRA User)
Type Bug
Environment

Xcode 11.2 on macOS 11.1

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 6f493812816ae17f68490d6e1f1e8cb0

Issue Description:

I am getting some incorrect code diagnostics. The error: "Variable being used before being initialization" appears on the lines labeled below.

struct MyButton<Label: View>: View {
    
    @State var label: Label
    @State var action: () -> Void
    
    var body: some View {...}
    
    init(action: @escaping () -> Void, @ViewBuilder label: () -> Label) {
        self.label = label() //Variable being used before being initialization
        self.action = action //Variable being used before being initialization
    }
    
}


extension MyButton where Label == Text {
    init<S>(_ title: S, action: @escaping () -> Void) where S : StringProtocol {
        self.label = Text(title) //Variable being used before being initialization
        self.action = action //Variable being used before being initialization
    }
}

I know this is wrong because if I remove the extension code, all 4 of the errors go away (even the ones not in the extension!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions