Closed
Description
Describe the bug
The compiler produces an error when it should not, in a context that involves opaque result types and primary associated types
To Reproduce
Steps to reproduce the behavior:
-
Compile this Swift snippet with Xcode 14 beta:
protocol Cursor<Element> { associatedtype Element } extension Cursor { func flatMap1<SegmentOfResult>(_ transform: @escaping (Element) throws -> SegmentOfResult) -> some Cursor<SegmentOfResult.Element> where SegmentOfResult: Cursor { // ❌ Return type of instance method 'flatMap1' requires that // 'SegmentOfResult.Element' conform to '(some Cursor).Element' map(transform).joined() } func flatMap2<T>(_ transform: @escaping (Element) throws -> some Cursor<T>) -> some Cursor<T> { // ❌ Return type of instance method 'flatMap2' requires that 'T' conform // to '(some Cursor).Element' map(transform).joined() } func map<T>(_ transform: @escaping (Element) throws -> T) -> some Cursor<T> { fatalError("not implemented") } } extension Cursor where Element: Cursor { func joined() -> some Cursor<Element.Element> { fatalError("not implemented") } }
-
See the erroneous compiler errors on the
flatMap1
andflatMap2
methods.
Expected behavior
flatMap1
should compileflatMap2
should probably compile as well (but I'm less comfortable with closure arguments that returnsome
, so I'm less sure).
Environment (please complete the following information):
- OS: macOS 12.4
- Xcode Version 14.0 beta (14A5228q)
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: generic declarations and typesFeature → types → opaque types: opaque result typesFeature → types: opaque typesFeature → protocol: protocols with primary associated typesFeature → type declarations: Protocol declarationsArea → compiler: Semantic analysisBug: Unexpected error