Skip to content

[SR-3417] #if in closure doesn't allow closure to be a single expression closure #46005

Closed
@swift-ci

Description

@swift-ci
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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfparserArea → compiler: The legacy C++ parsertype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions