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-6299] Throws/rethrows compilation error #48849

Closed
stephencelis opened this issue Nov 5, 2017 · 5 comments
Closed

[SR-6299] Throws/rethrows compilation error #48849

stephencelis opened this issue Nov 5, 2017 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0 type checker Area → compiler: Semantic analysis

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-6299
Radar rdar://problem/35368902
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Cannot Reproduce
Environment

Xcode 9.2 beta / Swift Trunk Snapshot (November 4)

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

md5: 117176693b6396be50616cb08b7c6219

Issue Description:

With all the moving parts, the following code fails to compile:

infix operator <|: infixr0
infix operator |>: infixl1

precedencegroup infixr0 {
  associativity: right
}
precedencegroup infixl1 {
  associativity: left
  higherThan: infixr0
}

func <| <A, B> (f: (A) throws -> B, a: A) rethrows -> B {
  return try f(a)
}
func |> <A, B> (a: A, f: (A) -> B) -> B {
  return try f(a)
}

struct Box<A> {
  let unbox: A
}
func suchThat<A>(_ x: Box<A>) -> (@escaping (A) -> A) -> Box<A> {
  return { f in Box(unbox: f(x.unbox)) }
}

Box(unbox: 1) |> suchThat <| { $0 + 1 }

The error:

error: ThrowsRethrows.playground:20:27: error: operator can throw but expression is not marked with 'try'
Box(unbox: 1) |> suchThat <| { $0 + 1 }
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~

ThrowsRethrows.playground:20:15: note: call is to 'rethrows' function, but argument function can throw
Box(unbox: 1) |> suchThat <| { $0 + 1 }
              ^

All of the following minor changes allow compilation:

  • Call the functions directly instead of using the operators

  • Remove throws/rethrows from <|

  • Use an unboxed type in suchThat, like A or Int

This appears to be a regression, as this code worked in a previous, beta version of Swift 4.

@belkadan
Copy link
Contributor

belkadan commented Nov 6, 2017

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Mar 7, 2018

At some point this appears to have started working again. I'm not sure what caused the regression or what restored the previous behavior, but this is probably a dup of another issue we fixed.

@stephencelis
Copy link
Contributor Author

Worth a regression test in the suite? 😃

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 26, 2018

@stephencelis, Good suggestion!

Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@rudkx
Copy link
Member

rudkx commented Jul 26, 2018

PR to add test: #18260

@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 regression swift 4.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants