-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfgenericsFeature: generic declarations and typesFeature: generic declarations and typesopaque result typesFeature → types → opaque types: opaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesFeature → types: opaque typesparameterized protocolsFeature → protocol: protocols with primary associated typesFeature → protocol: protocols with primary associated typesprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 6.2type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
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
flatMap1andflatMap2methods.
Expected behavior
flatMap1should compileflatMap2should 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
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfgenericsFeature: generic declarations and typesFeature: generic declarations and typesopaque result typesFeature → types → opaque types: opaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesFeature → types: opaque typesparameterized protocolsFeature → protocol: protocols with primary associated typesFeature → protocol: protocols with primary associated typesprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 6.2type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error