Why isn't a private var in Swift struct available in #if'd init for that struct?

Answered
While doing some research on ncurses and how to use it in Swift, I took a look at IOGUI[1].
 
It wouldn't compile properly, so I began clearing warnings and errors.
 
That's when I came across what may be some Swift subtleness that I'm unaware of.
 
> Note: I'm not discussing compilation errors below. This question is specific to the parsing done by Xcode to indicate warnings and errors in the code editor.
 
Referring to the following struct:
 
```swift
public struct MenuWidget {
 
    var widgetRows: Int
    // CUT
    private var startRow: Int
 
#if os(Linux)
    public init(startRow: Int, widgetSize: Int, choices: [GUIMenuChoices], delegate: @escaping MenuChoicesSelectionDelegate, mainWindow: UnsafeMutablePointer<WINDOW>) {
 
        self.startRow = startRow
        // CUT
        initWindows()
    }
#else
    public init(startRow: Int, widgetSize: Int, choices: [GUIMenuChoices], delegate: @escaping MenuChoicesSelectionDelegate, mainWindow: OpaquePointer) {
 
        self.startRow = startRow
        // CUT
        initWindows()
    }
#endif
 
    // CUT
} // END STRUCT
```
 
Within the `#if os(Linux)` section, `self.startRow` is marked as inaccessible from that scope.
 
Yet in the `#else`, there is no error indicated. `widgetRows` is accessible in both the `#if` and `#else`
 
If I remove private from the `startRow` declaration, then it's fine in both scopes. But that makes the variable `internal` and makes it accessible outside of the struct, which is incorrect.
 
It could also just be the behavior of the Swift `#if` construct that I'm not familiar with.
 
I've searched the usual places, including here at SO. Nothing similar deals with this particular scenario, at least not with the search terms I used.
 
Any hints or tips would be appreciated.
 
P.S. If you want to check out the IOGUI[1] source, I'm specifically referring to lines 41 and 78-100 (inclusive) of MenuWidget.swift. A second example are lines 72-108 (inclusive) of InputPopupWidget.swift.
 
 
 
1 comment
Comment actions Permalink
Official comment

Hi David,

Created OC-18354 per you report. Please watch the ticket.

Please sign in to leave a comment.