# \[Pitch\] if and switch expressions

**URL:** <https://forums.swift.org/t/pitch-if-and-switch-expressions/61149>\
**Category:** Pitches\
**Created:** [October 31, 2022, 9:57pm UTC](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149 "2022-10-31T21:57:39Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Paul\_Cantrell](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/paul_cantrell/32/16764_2.png) [@Paul\_Cantrell](https://forums.swift.org/u/Paul_Cantrell)\
**Post date:** [October 31, 2022, 11:06pm UTC](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149/11 "2022-10-31T23:06:23Z")

</div>

I am delighted to see this much-needed proposal seeing the light of day at last! It is indeed a conspicuous gap.

I have two suggestions, which I’ll post in separate messages to avoid reply confusion. First suggestion:

**Consider allowing conditionals in arbitrary expression positions when enclosed in parentheses.**

The lack of full generality of the proposal as it stands is bothersome to me.

What if we took this proposal as is for the 3 allowed cases — returns, assignments, and declaration initializers — but then allowed if / switch expressions in arbitrary other positions if and only if enclosed in parentheses? Thus:

```swift
var x = 1 + if foo { y } else { z } // not allowed

var x = 1 + (if foo { y } else { z }) // allowed

```

Thus the potentially ambiguous example in the proposal’s Future Directions section retains its original, current meaning:

```swift
VStack {
    if showButton {
        Button("Click me!", action: clicked)
    } else {
        Text("No button")
    }
    .someProperty
}

```

…because parentheses (currently illegal, thus no breakage!) would be necessary to get `someProperty` of the `Button` / `Text` values from the conditional:

```swift
VStack {
    (if showButton {
        Button("Click me!", action: clicked)
    } else {
        Text("No button")
    })
    .someProperty // One would probably format this on the same
                   // line as `)`; just making the point that
                   // the ambiguity the proposal mentions is resolved.
}

```

---

_[View the full topic](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149)._
