[Pitch 2] Light-weight same-type requirement syntax

So I would expect that this syntax would preserve throwing semantics of the type. Specifically for this to be useful for AsyncSequence (which do not misconstrue my critique... this is VERY important for AsyncSequence... no one really wants to write .eraseToAnyPublisher() over and over...) it needs to preserve the throwyness or non-throwyness of the base type. As of current the implementation does not seem to do so.

Is that a consideration that is going to be accounted for in this proposal?

Here is an example I just ran on nearly top of tree and sadly it seems to fail:


@rethrows
protocol Foo {
  @_primaryAssociatedType associatedtype Element
  func bar() throws -> Element
}

struct NonthrowingFoo: Foo {
  func bar() -> String {
    return "bar"
  }
}

func testNonthrowing() -> some Foo<String> {
  NonthrowingFoo()
}

print(testNonthrowing().bar()) // call can throw but is not marked with 'try' 

It is worth noting that this does not require the @rethrows to be there for the behavior to incorrectly propagate.

3 Likes