Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7229] Unexpected ambiguity error #49777

Closed
nevil opened this issue Mar 19, 2018 · 7 comments
Closed

[SR-7229] Unexpected ambiguity error #49777

nevil opened this issue Mar 19, 2018 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2 type checker Area → compiler: Semantic analysis

Comments

@nevil
Copy link

nevil commented Mar 19, 2018

Previous ID SR-7229
Radar rdar://problem/38641996
Original Reporter @nevil
Type Bug
Status Closed
Resolution Done
Environment

swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain

iOS SDK from Xcode 9.2:
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk

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

md5: 8600a956a0c0a5ab22f49113a8df937b

relates to:

  • SR-7235 "nearly matches optional requirement" warning for correct function signature from protocol UICollectionViewDelegate

Issue Description:

The below code generates an unexpected error:

Error:

bug.swift:22:17: error: ambiguous use of 'convert(_:to:)'
        let p = sender.convert(sender.bounds, to: collectionView)
//

import UIKit

class ACollectionViewDelegate: NSObject, UICollectionViewDelegate {
    var collectionView: UICollectionView! { return UICollectionView() }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 0
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return UICollectionViewCell()
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    }
}

final class Reproducer: ACollectionViewDelegate {
    @objc private func buttonAction(_ sender: UIButton) {
        let p = sender.convert(sender.bounds, to: collectionView)
    }
}

Builds fine with Swift from Xcode 9.2 (Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)) but fails with swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain.

Full invocation and output:

Apple Swift version 4.2-dev (LLVM cef3fe6d75, Clang bdc970d89c, Swift 931d06d1cc)
Target: arm64-apple-ios10.0
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain/usr/bin/swift -frontend -c -primary-file bug.swift -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -color-diagnostics -module-name bug -o bug.o
bug.swift:12:10: warning: instance method 'collectionView(_:cellForItemAt:)' nearly matches optional requirement 'collectionView(_:canFocusItemAt:)' of protocol 'UICollectionViewDelegate'
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         ^
bug.swift:12:10: note: candidate has non-matching type '(UICollectionView, IndexPath) -> UICollectionViewCell'
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         ^
bug.swift:12:10: note: move 'collectionView(_:cellForItemAt:)' to an extension to silence this warning
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         ^
bug.swift:12:10: note: make 'collectionView(_:cellForItemAt:)' private to silence this warning
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         ^
    private
UIKit.UICollectionViewDelegate:63:26: note: requirement 'collectionView(_:canFocusItemAt:)' declared here
    optional public func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool
                         ^
bug.swift:22:17: error: ambiguous use of 'convert(_:to:)'
        let p = sender.convert(sender.bounds, to: collectionView)
                ^
UIKit.UIView:61:15: note: found this candidate
    open func convert(_ rect: CGRect, to coordinateSpace: UICoordinateSpace) -> CGRect
              ^
UIKit.UIView:26:15: note: found this candidate
    open func convert(_ rect: CGRect, to view: UIView?) -> CGRect
              ^
@nevil
Copy link
Author

nevil commented Mar 19, 2018

The error goes away if I cast the collectionView property from "UICollectionView!" to a UICollectionView:

+        let p = sender.convert(sender.bounds, to: collectionView as UICollectionView)

or if I remove one of the UICollectionViewDelegate methods from ACollectionViewDelegate.

@belkadan
Copy link
Contributor

cc @rudkx for the convert(_:to:) one and @DougGregor for the "nearly matches" one.

@belkadan
Copy link
Contributor

Actually, can you split out one of these into a separate bug? They're not related.

@nevil
Copy link
Author

nevil commented Mar 19, 2018

Thanks @belkadan!

I created SR-7235 for the warning.
It was a lazy "drive-by" comment that I should have created a separate ticket for in the first place...

@belkadan
Copy link
Contributor

Thanks, so this is about the issue with the IUO UICollectionView.

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Apr 12, 2018

Resolved by #15881

@nevil
Copy link
Author

nevil commented Apr 13, 2018

Confirmed fixed in swift-DEVELOPMENT-SNAPSHOT-2018-04-12-a.xctoolchain

Thanks!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants