Skip to content
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

[SR-5641] Playgrounds don't display output for defer statements #48211

Closed
swift-ci opened this issue Aug 7, 2017 · 2 comments
Closed

[SR-5641] Playgrounds don't display output for defer statements #48211

swift-ci opened this issue Aug 7, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PlaygroundTransform

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Aug 7, 2017

Previous ID SR-5641
Radar rdar://problem/33764082
Original Reporter joedecapo (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

OS: macOS Sierra 10.12.6

Reproduced on Xcode 8.3.3 with Swift 3.2 and on Xcode 9 beta 5 with Swift 4.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, PlaygroundTransform
Assignee None
Priority Medium

md5: 00c19da058773aefaeecec1ab06085f4

Issue Description:

I was trying to use the `defer` statement in a Playground, and was surprised to find that it never prints anything in the preview pane on the side. I was expecting the evaluation of the code in the `defer` statement to show up in line with the statements, even though they're executed after the last line in the function. I made a very simple playground that modifies a global variable and prints the value in the `defer` statement, and when I print the global variable after calling my function it shows the correct updated value, so the code in the `defer` statement is getting run as expected. Here's my sample code with the Playground output in comments on the side:

var x = 3            // 3
func doSomething() {
  print(1)           // "1\n"
  defer {
      x += 1
      print(x)
  }
  print(2)           // "2\n"
}
doSomething()
print(x)             // "4\n"

I was expecting something like this:

var x = 3            // 3
func doSomething() {
  print(1)           // "1\n"
  defer {
      x += 1         // 4
      print(x)       // "4\n"
  }
  print(2)           // "2\n"
}
doSomething()
print(x)             // "4\n"

The relevant playground is attached to this issue.

@belkadan
Copy link
Contributor

belkadan commented Aug 7, 2017

Of course, the first thing I'm going to do with the JIRA is pull it into Radar, but at least this way other people outside of Apple may be able to investigate too!

@swift-ci create

@belkadan
Copy link
Contributor

Connor fixed this and cherry-picked to Swift 4.1 in #13885

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PlaygroundTransform
Projects
None yet
Development

No branches or pull requests

2 participants