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-7425] ambiguity error when class constraining protocol extension fulfills protocol requirement #49968

Closed
nevil opened this issue Apr 13, 2018 · 6 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.1

Comments

@nevil
Copy link

nevil commented Apr 13, 2018

Previous ID SR-7425
Radar None
Original Reporter @nevil
Type Bug
Status Closed
Resolution Done
Environment

Fails in swift-DEVELOPMENT-SNAPSHOT-2018-04-12-a.xctoolchain
Works in "Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)"

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.1Regression
Assignee @hamishknight
Priority Medium

md5: d734e2e0a61ae390ce066c2f52dedc35

is duplicated by:

  • SR-8944 Ambiguous use in constrained protocol extension

relates to:

  • SR-7126 Swift 4.1 protocol overlap ambiguous property

Issue Description:

Sorry if my summary is incorrect.

We have code that looks like this:

class C {}

extension C {
    var integer: Int { return 1 }
}

protocol P {
    var integer: Int { get }
}

extension P where Self: C {
    var anotherInteger: Int { return self.integer }
}

This compiles with "Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)".
With swift-DEVELOPMENT-SNAPSHOT-2018-04-12-a.xctoolchain this gives error:

bug.swift:13:38: error: ambiguous use of 'integer'
    var anotherInteger: Int { return self.integer }
                                     ^
bug.swift:4:9: note: found this candidate
    var integer: Int { return 1 }
        ^
bug.swift:8:9: note: found this candidate
    var integer: Int { get }
        ^

The ambiguity can be resolved by making sure that self is of type C:

var anotherInteger: Int { return (self as C).integer }

Is this ambiguity error the expected behavior?

@nevil
Copy link
Author

nevil commented Apr 13, 2018

Maybe related to SR-7126 ?

@belkadan
Copy link
Contributor

Yes, I think the ambiguity error is correct. @hamishknight recently fixed some issues that could have hid this, but it's unclear what the compiler was doing in 4.0!

@belkadan
Copy link
Contributor

cc @DougGregor too

@hamishknight
Copy link
Collaborator

After some discussion over at https://forums.swift.org/t/xcode-10-changed-behaviour-of-class-and-protocol-existential/15062, I think we should make this unambiguous (favouring the member on the concrete type) – I have opened a PR here: #18927

@hamishknight
Copy link
Collaborator

Resolved by #18952 (for Swift 4 mode) and #18951 (for Swift 5 mode).

@nevil
Copy link
Author

nevil commented Jan 6, 2021

Sorry for the late confirmation.
Confirmed fixed.

@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.1
Projects
None yet
Development

No branches or pull requests

4 participants