# SE-0345: \`if let\` shorthand for shadowing an existing optional variable

**URL:** <https://forums.swift.org/t/se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/55805>\
**Category:** Proposal Reviews\
**Created:** [March 8, 2022, 11:24pm UTC](https://forums.swift.org/t/se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/55805 "2022-03-08T23:24:15Z")\
**Posts on this page:** 1\
**Showing post:** 41

<div class="post-metadata">

**Author:** ![cal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cal/32/35557_2.png) [@cal](https://forums.swift.org/u/cal)\
**Post date:** [March 10, 2022, 2:57pm UTC](https://forums.swift.org/t/se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/55805/41 "2022-03-10T14:57:25Z")

</div>

> [@Jumhyn](#):
>
> Just wanted to elaborate a bit on why I'm not _super_ compelled by the proposal's arguments against `if let foo?`

Agreed that most of the style-related arguments here are pretty subjective. For the default case I think `if let foo` and `if let foo?` are both totally reasonable.

I do think `if let foo` meshes more nicely with other syntax / features adjacent to optional unwrapping. Support for explicit type annotations is one example currently included in the proposal / implementation:

```swift
if let foo: Foo { ... }

```

This falls out completely naturally from the change to the grammar, which is to just make the RHS optional. Disallowing this here would make the grammar a bit more complicated / less generalized.

For consistency with other `let`s / `var`s in the language, it seems desirable to support type annotations here unless we have a really compelling reason to disallow them. This was [brought up in the pitch thread](https://forums.swift.org/t/if-let-shorthand/54230/39), as one example.

A future direction mentioned in the proposal is support for optional casting:

```swift
if let foo as? Bar { ... }

// as potential future shorthand for 
if let foo = foo as? Bar { ... }

```

I think both of these syntax extensions are a a bit more unnatural with an additional `?` symbol:

```swift
if let foo?: Foo { ... }

if let foo? as? Bar { ... }

```

---

_[View the full topic](https://forums.swift.org/t/se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/55805)._
