Skip to content

[SR-4685] Can't infer associatedtypes with where clause #47262

@rintaro

Description

@rintaro
mannequin
Previous ID SR-4685
Radar rdar://problem/39040799
Original Reporter @rintaro
Type Bug
Environment

Swift version 3.1-dev (LLVM 1067090d70, Clang 5e8cb0e694, Swift f83d1a7)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @DougGregor
Priority Medium

md5: 3fae0cb45075895bc8535a198c649e47

is duplicated by:

Issue Description:

The current master doesn't compile this.

protocol MySequence {
  associatedtype Element
  associatedtype Iterator: IteratorProtocol where Iterator.Element == Element
  func makeIterator() -> Iterator
}

struct Foo {}

struct FooIterator : IteratorProtocol {
  func next() -> Foo? { return Foo() }
}

struct FooSequence : MySequence {
  func makeIterator() -> FooIterator {
    return FooIterator()
  }
}

results:

test.swift:13:8: error: type 'FooSequence' does not conform to protocol 'MySequence'
struct FooSequence : MySequence {
       ^
test.swift:2:18: note: protocol requires nested type 'Element'; do you want to add it?
  associatedtype Element
                 ^
test.swift:3:18: note: protocol requires nested type 'Iterator'; do you want to add it?
  associatedtype Iterator: IteratorProtocol where Iterator.Element == Element
                 ^

This is basically the same structure as #8939.

Metadata

Metadata

Assignees

Labels

associated type inferencebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesgeneric constraintsFeature → generics: generic constraintsgenericsFeature: generic declarations and typesswift 5.10type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions