Skip to content

Cannot suppress Escapable requirement on associated types #85773

@ahoppen

Description

@ahoppen

Suppose I have a custom sequence type like

public struct MySequence<Element: ~Escapable> {
  @inlinable
  public func forEach<Error>(_ body: (Element) throws(Error) -> Void) throws(Error) {
    fatalError("TODO")
  }
}

Now, I would naïvely write this as follows

public protocol MySequenceProtocol {
    associatedtype Element: ~Copyable // error: Cannot suppress 'Copyable' requirement of an associated type

    func forEach(_ body: (Element) -> Void)
}

Removing the ~Copyable constraint on the associated type gives me the following errors:

public struct MySequence<Element: ~Escapable>: MySequenceProtocol { // error: type 'MySequence<Element>' does not conform to protocol 'MySequenceProtocol'
    @inlinable
    public func forEach(_ body: (Element) -> Void) { // note: note: candidate can not infer 'Element' = 'Element' because 'Element' is not a nominal type and so can't conform to 'Escapable'
        fatalError("TODO")
    }
}

As far as I can tell, there’s no way to model this at the moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ownershipFeature: Ownership modifiers and semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions