Skip to content

[SR-11417] Failure to infer associated type #53818

Open
@jeremyabannister

Description

@jeremyabannister
Previous ID SR-11417
Radar rdar://problem/55114221
Original Reporter @jeremyabannister
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AssociatedTypeInference
Assignee None
Priority Medium

md5: 001072ec536c5ffe7ab2fefe44ba1db9

Issue Description:

This code fails to compile with swift 5:

protocol A {
    associatedtype Value
}

protocol B: A {
    func f (x: Any?) -> Value?
}

struct C: B {
    func f (x: Any?) -> String? {
        return nil
    }
}

The error is:

Type 'C' does not conform to protocol 'A'

Simply adding this:

typealias Value = String

to C fixes error. I was very surprised about this, as this seems like quite a basic type inference situation. Am I missing something or is this simply a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    associated type inferencebugA 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