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-5147] Ambiguous use error on swift 3.1 #47723

swift-ci opened this issue Jun 7, 2017 · 2 comments

[SR-5147] Ambiguous use error on swift 3.1 #47723

swift-ci opened this issue Jun 7, 2017 · 2 comments


Copy link

@swift-ci swift-ci commented Jun 7, 2017

Previous ID SR-5147
Radar None
Original Reporter (JIRA User)
Type Bug

Doesn't compile on swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Compiles on version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, TypeChecker
Assignee None
Priority Medium

md5: b9a321561ba06abadf6df1295ba95e70

Issue Description:

The code example below used to compile on swift 3.0, but won' t compile on 3.1:

class C {
    public static func decode<T: Hashable>(_ odata: Data?, context: Int) -> T? {
        return nil
    public static func decode<T: Hashable>(_ data: Data, context: Int) -> T {
        return (decode(data, context: 10) as T?)!

The error message is:

error: ambiguous use of 'decode(_:context:)'
        return (decode(data, context: 10) as T?)!
Copy link

@belkadan belkadan commented Jun 7, 2017

That does look ambiguous: either it can put data into an Optional, or it can put the result into an Optional. I wonder which one Swift 3.0 was picking.

Copy link
Collaborator Author

@swift-ci swift-ci commented Jun 8, 2017

Comment by Tamas Kovacs (JIRA)

Our intention was to call the first method, that returns an optional, hence the "as T?" in the code. This is also what swift 3.0 does.

I guess it is kind of ambiguous, since that call could mean "call the second method, and then cast the result to T?".

However there are also a few changes that cause this code compile, that have seemingly no relation to this ambiguity.
For example removing the context parameter, or removing the Hashable type constraint.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants