Skip to content

[5.9] [Changelog] Add changelog entry for SE-0380 #65888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2023

Conversation

hamishknight
Copy link
Contributor

5.9 cherry-pick of #65887

SE-0380

@hamishknight hamishknight added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels May 12, 2023
@hamishknight hamishknight requested a review from a team as a code owner May 12, 2023 10:39
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@airspeedswift airspeedswift merged commit 0acd423 into swiftlang:release/5.9 May 13, 2023
@hamishknight hamishknight deleted the changelog-5.9 branch May 13, 2023 13:31
@altairdeark
Copy link

altairdeark commented Aug 10, 2023

Hi @hamishknight , i am facing an issue with SE-0380 and latest xcode Beta. Now Return have unexpected behavior in case if if or switch used after it.

Compilable

func test() {
          print('1')
          return /// expect the end of progamm here

          if true {
               print('2') /// still will be executable, bcs `if` now is equal to `()`
          } else {
               print('3')
          }

          return
}

Result:

1
2

2 is unexpected

I believe Swift update should complement rather than break the existing one. Is it a known issue?

@hamishknight
Copy link
Contributor Author

@altairdeark This is expected, see https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md#source-compatibility:

As proposed, this addition has one source incompatibility, related to unreachable code. The following currently compiles, albeit with a warning that the if statement is unreachable (and the values in the branches unused):

func foo() {
  return
  if .random() { 0 } else { 0 }
}

The code provided produces the following warning:

func test() {
  print("1")
  return

  if true { // warning: expression following 'return' is treated as an argument of the 'return'
    print("2")
  } else {
    print("3")
  }

  return
}

@altairdeark
Copy link

altairdeark commented Aug 11, 2023

@hamishknight ,

Still it is breaks the old code, and not everyone will recheck whole code base to fix this warning, since in older project i have 1000+ warnings (legacy). In my case in if i was having an unexpected server API calls which was a total surprise for me since i was not aware of SE-0380. I believe it could also breaks others project, libs and else.

Do we have any option to solve it? like: when after return we have a new line or \r, so it should not treat If as an argument for return and just behave as it was.

@hamishknight
Copy link
Contributor Author

@altairdeark You can add a ; to the end of the return to avoid treating the following expression as part of the return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants