SwifterSwift / SwifterSwift

A handy collection of more than 500 native Swift extensions to boost your productivity.
https://swifterswift.com
MIT License
13.83k stars 1.61k forks source link

Getting `ambiguous use of 'makeIterator()'` error when building package with Xcode 14 #1042

Closed ianclawson closed 1 year ago

ianclawson commented 1 year ago

Describe the bug The package will fail to build and install when used inside a project being compiled on Xcode 14 beta, with an ambiguous use of 'makeIterator()' error.

To Reproduce

  1. Add SwifterSwift as a package inside an iOS project.
  2. Open project in Xcode 14 beta.
  3. Attempt to build app.

Expected behavior The SwifterSwift package will not fail to build when using Xcode 14 beta.

Additional context

Here's a screenshot of the error:

Screen Shot 2022-08-31 at 10 07 12 AM

I'm about to open a PR which addresses this issue!

LucianoPAlmeida commented 1 year ago

What is the error we see?

ianclawson commented 1 year ago

I just updated the description with the text error and a screenshot in addition to the title for more context. 🙏

ianclawson commented 1 year ago

Also here's my PR solution: https://github.com/SwifterSwift/SwifterSwift/pull/1043

LucianoPAlmeida commented 1 year ago

The error is saying which overloads of makeIterator() are ambiguous? I'm just curious to know because the fix would be try to disambiguate this a compile time ... I guess

theedov commented 1 year ago

Any news on this?

LucianoPAlmeida commented 1 year ago

Any news on this?

Sorry, I wasn't able to download the beta as I wanted to understand better the issue before reviewing the PR.

ianclawson commented 1 year ago

I'm currently out of town and can't followup at the moment, unfortunately. I don't recall which two overloads of makeIterator() are ambiguous.

Anyone with the beta should be able to pull up the same error though, if someone wanted to look into if before I'm back next week.

theedov commented 1 year ago

Does this help?

Screenshot 2022-09-06 at 11 58 06 am
LucianoPAlmeida commented 1 year ago

Yes a little bit, in the sense that I guess for byte: UInt8 in self {would disambiguate that call. Can you give that a shot and confirm if that works? If it does, change the PR to that? I'm still not sure how that is ambiguous since the one on Disgest should be an specialization on Sequence... so that is confusing.

theedov commented 1 year ago

Yes a little bit, in the sense that I guess for byte: UInt8 in self {would disambiguate that call. Can you give that a shot and confirm if that works? If it does, change the PR to that? I'm still not sure how that is ambiguous since the one on Disgest should be an specialization on Sequence... so that is confusing.

Just tried it, doesn't work.

image
LucianoPAlmeida commented 1 year ago

How about that for elt in self.makeIterator()? I just found out that this is a compiler regression bug

LucianoPAlmeida commented 1 year ago

This is the reduced reproducer:

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)
    }
  }
}

I've already reported the bug on https://github.com/apple/swift/issues/

theedov commented 1 year ago

How about that for elt in self.makeIterator()? I just found out that this is a compiler regression bug

Yeah, that works.

LucianoPAlmeida commented 1 year ago

Nice, for the reference this is the bug: https://github.com/apple/swift/issues/60958 But I guess we can have this as a work around for now =]

theedov commented 1 year ago

Nice, for the reference this is the bug: apple/swift#60958 But I guess we can have this as a work around for now =]

Created a PR for this one. https://github.com/SwifterSwift/SwifterSwift/pull/1045

LucianoPAlmeida commented 1 year ago

Workaround changes landed! Was actually an interesting compiler bug finding Thank you @ianclawson @theedov

ianclawson commented 1 year ago

Not sure why a separate PR was created when my PR was already open and essentially the same solution. But I've closed it since it's now redundant. https://github.com/SwifterSwift/SwifterSwift/pull/1043

Thanks for bringing this to a close.