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-3417] #if in closure doesn't allow closure to be a single expression closure #46005

Closed
swift-ci opened this issue Dec 14, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself parser Area → compiler: The legacy C++ parser type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3417
Radar None
Original Reporter hughbe (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Parser, TypeChecker
Assignee maustinstar (JIRA)
Priority Medium

md5: 9e8c4f62db5afe1e6df957fc5c116a33

Issue Description:

The following code feels like it should work, but doesn't

public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) {
  var fds: [CInt] = [0, 0]
  let ret = fds.withUnsafeMutableBufferPointer { unsafeFds -> CInt in
#if !os(Windows) || CYGWIN
    pipe(unsafeFds.baseAddress)
#else
    _pipe(unsafeFds.baseAddress, 0, 0)
#endif
  }
  return (readEnd: fds[0], writeEnd: fds[1], error: ret)
}

Instead, you need to include an explicit return as the closure can no longer be a single expression closure.

public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) {
  var fds: [CInt] = [0, 0]
  let ret = fds.withUnsafeMutableBufferPointer { unsafeFds -> CInt in
#if !os(Windows) || CYGWIN
    return pipe(unsafeFds.baseAddress)
#else
    return _pipe(unsafeFds.baseAddress, 0, 0)
#endif
  }
  return (readEnd: fds[0], writeEnd: fds[1], error: ret)
}
@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 3, 2020

Comment by Michael Verges (JIRA)

PR: #34510

@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 itself parser Area → compiler: The legacy C++ parser type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant