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

Good point. Could be this then:

1) shadowing let x = y     <--->  let x = y // x was defined in an outer block
2) shadowing let x         <--->  let x = x
3) shadowing let x = 2*x   <--->  let x = 2*x
4) let x = x                      // ❌ error: use explicit shadowing
5) let x = 2*x                    // ❌ error: add explicit shadowing
6) shadowing let x = x            // ❌ error or warning: remove "= x"
7) let yourSurname = yourSurname  // ❌ error: use explicit shadowing
8) let yоurSurname = yourSurname  // ok (homograph spoofing "о" vs "o")

ditto for if / guard and var.

provided (4) & (7) will get out of favour in the future due to warning / error, the homograph spoofing attacks would be much more obvious (the "let x = y" pattern would be reserved for cases when x and y are different).

Edit: changed "shadow" to "shadowing" to be inline with weak/mutating/etc.

2 Likes