Skip to content

[Regression] Ambiguous makeIterator() in 5.7 #60958

Closed
@LucianoPAlmeida

Description

@LucianoPAlmeida

Describe the bug
The following snippet

struct S: Sequence {
  private var _storage: [UInt8] = []
  func makeIterator() -> Array<UInt8>.Iterator {
    _storage.makeIterator()
  }
  
  typealias Element = UInt8
  class Iterator: IteratorProtocol {
    func next() -> UInt8? { 0 }
    typealias Element = UInt8
  }

  func makeIterator() -> Iterator {
    Iterator()
  }
}

extension S {
  func f() {
    for elt in self { //  error: ambiguous use of 'makeIterator()'
      print(elt)
    }
  }
}

Steps To Reproduce
Steps to reproduce the behavior:

  1. Open this on Compiler Explorer https://godbolt.org/z/7seohEf8K
  2. Note that in 5.6 that compiles but 5.7 and main nightly it gives as ambiguous makeIterator()
    ...

Expected behavior
Should compile

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please fill out the following information)

  • OS: [e.g. macOS 11.0]
  • Xcode Version/Tag/Branch:

Additional context

...
Resolved overloads:
  selected overload set choice self: $T0 == S for locator@0xbbc9e48 [DeclRef@<source>:23:16]
  selected overload set choice $elt$generator: $T4 == @lvalue $T2 for locator@0xbbca298 [DeclRef@<invalid loc>]
  ($T6 [attributes: delayed] [involves_type_vars: $T8] [with possible bindings: (subtypes of) $T8?])
  (attempting disjunction choice $T1 bound to decl output.(file).S.makeIterator()@<source>:4:8 : (S) -> () -> Array<UInt8>.Iterator [[locator@0xbbc9eb8 [UnresolvedDot@<source>:23:16 -> member]]];
    (overload set choice binding $T1 := () -> Array<UInt8>.Iterator)
    (overload set choice binding $T5 := () -> $T9.Element?)
    (attempting disjunction choice UInt8? bind $T8? [deep equality] [[locator@0xbbca5c0 [DeclRef@<source>:23:16 -> sequence element type -> optional payload]]];
      ($T7 [with possible bindings: (supertypes of) UInt8])
      Initial bindings: $T7 := UInt8
      (attempting type variable $T7 := UInt8
        (found solution: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>)
      )
    )
  )
  (attempting disjunction choice $T1 bound to decl output.(file).S.makeIterator()@<source>:14:8 : (S) -> () -> S.Iterator [[locator@0xbbc9eb8 [UnresolvedDot@<source>:23:16 -> member]]];
    (overload set choice binding $T1 := () -> S.Iterator)
    (overload set choice binding $T5 := () -> UInt8?)
    (attempting disjunction choice UInt8? bind $T8? [deep equality] [[locator@0xbbca5c0 [DeclRef@<source>:23:16 -> sequence element type -> optional payload]]];
      ($T7 [with possible bindings: (supertypes of) UInt8])
      Initial bindings: $T7 := UInt8
      (attempting type variable $T7 := UInt8
        (found solution: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>)
      )
    )
  )
  (attempting disjunction choice $T1 bound to decl Swift.(file).Sequence extension.makeIterator() : <Self where Self : Sequence, Self == Self.Iterator> (__owned Self) -> () -> Self [[locator@0xbbc9eb8 [UnresolvedDot@<source>:23:16 -> member]]];
    (failed constraint $T10 bind $T10.Iterator [[locator@0xbc10788 [UnresolvedDot@<source>:23:16 -> member -> opened generic -> type parameter requirement #1 (same-type)]]];)
    (overload set choice binding $T1 := () -> $T10)
  )

Maybe there is a bit more to it, but is a bit strange that the overload that is not the one from Sequence conformance is being considered here and even if considered how it is ending up with the same score.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselftype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions