[Accepted with modifications] SE-0380: `if` and `switch` expressions

Yes, the Language Workgroup discussed if and switch expressions in arbitrary subexpressions. We ultimately agreed with the proposal authors' decision to subset arbitrary subexpressions out of the proposal, as we anticipate the current proposal covers the majority of cases where this feature will reduce ceremony. The proposal authors also clarified during the review that if and switch expressions can be nested, which assuaged some reviewers' concerns about the limitation.

The Language Workgroup is primarily concerned with whether a given proposal closes off compelling future directions. Generalizing this feature to arbitrary subexpressions certainly can happen in a future proposal, but the Language Workgroup does not decide whether a future direction in a given proposal will definitively be pursued.

Writing return statements inside if or switch expressions is not accepted:

func test() -> Int {
  let value = if true { 
    0 
  } else { 
    return 1  // not allowed
  }

  return value + 10
}
7 Likes