Skip to content

[SR-3145] Compiler reports ambiguous type inference when not ambiguous #45733

@swift-ci

Description

@swift-ci
Previous ID SR-3145
Radar None
Original Reporter ellneal (JIRA User)
Type Bug
Environment

Swift 3.0.1
Xcode 8.1 (8B62)
macOS 10.12.1

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

md5: b543b9861b9acc9be7a5739c0a9e33f8

Issue Description:

I'm prefacing this by saying that I know this is an overly complicated example, but I think the compiler is wrong in saying that this is ambiguous.

class Root { }

protocol Generic {
    associatedtype RootType: Root
    var root: RootType { get }
}

extension Generic where Self: Root {
    var root: Self {
        return self
    }
}

class Leaf: Root { }

protocol Specialised { }
extension Specialised where Self: Generic {
    var root: Leaf {
        get {
            return Leaf()
        }
    }
}

class Implementation: Generic, Specialised {
    // errors:
    //   Ambiguous inference of associated type 'RootType': 'Leaf' vs. 'Implementation'
    //   Matching requirement 'root' to this declaration inferred associated type to 'Leaf'
    //   Matching requirement 'root' to this declaration inferred associated type to 'Implementation'
}

I believe that if Implementation also inherited from Root this would be ambiguous, but not in the current state (as far as I can tell).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions