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-10093] Bugs around coercing errors #52495

Closed
stephencelis opened this issue Mar 12, 2019 · 2 comments
Closed

[SR-10093] Bugs around coercing errors #52495

stephencelis opened this issue Mar 12, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-10093
Radar None
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 5 (Xcode 10.2 beta 4)

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

md5: f5630b5a325b8fd4c743d8339125feb2

duplicates:

  • SR-10015 values.map(Result.success) raises assertion failure

Issue Description:

Given the following Either type:

public enum Either<Left, Right> {
  case left(Left)
  case right(Right)

  public func either<A>(ifLeft: (Left) throws -> A, ifRight: (Right) throws -> A) rethrows -> A {
    switch self {
    case let .left(left):
      return try ifLeft(left)
    case let .right(right):
      return try ifRight(right)
    }
  }
} 

The following code appears to put the compiler into an infinite loop:

 extension Either where Left: Error {
  public var asRightResult: Result<Right, Error> {
    return self.either(ifLeft: Result.failure, ifRight: Result.success)
  }
}

extension Either where Right: Error {
  public var asLeftResult: Result<Left, Error> {
    return self.either(ifLeft: Result.success, ifRight: Result.failure)
  }
}

Meanwhile, opening closures to allow the types to coerce causes a segfault:

extension Either where Left: Error {
  public var asRightResult: Result<Right, Error> {
    return self.either(ifLeft: { Result.failure($0) }, ifRight: Result.success)
  }
}

extension Either where Right: Error {
  public var asLeftResult: Result<Left, Error> {
    return self.either(ifLeft: Result.success, ifRight: { Result.failure($0) })
  }
}
@belkadan
Copy link
Contributor

On master, with assertions:

Assertion failed: (isa<ArchetypeType>(type)), function addProtocolConformance, file /Volumes/Data/swift-public/swift/lib/IRGen/GenProto.cpp, line 2869.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin18.5.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode10.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--7dafe9.o 
1.  While emitting IR SIL function "@$s4main6EitherOAAs5ErrorRzrlE13asRightResults0F0Oyq_sAD_pGvg".
 for getter for asRightResult (at <stdin>:16:14)

More Error self-conformance issues, I guess (as noted). @rjmccall?

@belkadan
Copy link
Contributor

Consolidating.

@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
Projects
None yet
Development

No branches or pull requests

2 participants