Non-actionable warning when trying to extend a protocol with a typealias

Hi there. I have a piece of code-generated code and I don't have an easy way to rename some of the generated entities (this is OpenAPI-generator w/ mustache which is quite limited on purpose).

So to set on a generic problem let's say I have:

protocol P1 {
    associatedtype T1
}

protocol P2: P1 {
    associatedtype T2
}

Then the code-generated piece I can arrive to looks like:

class C2: P2 {
    typealias T2 = Int
}

so I was hoping to be able to express that actually T1 = T2, so I just went with:

extension P2 {
    typealias T1 = T2
}

this works (yey!) but now I'm getting a non-actionable warning/suggestion that says:
Typealias overriding associated type 'T1' from protocol 'P1' is better expressed as same-type constraint on the protocol
and the fix it offers is:

remove extension P2 and change P2 definition to protocol P2: P1 where T1 == T2 {.

but the problem is that this doesn't seem to be arriving to the same effect. as soon as I do that C2 fails with Type 'C2' does not conform to protocol 'P1'

So I was wondering if a) I can mute the warning or b) if there's any other way I could express this. Thanks!

PS: FB13855880

1 Like

For what it's worth, it seems to compile fine with the Swift 6 compiler (tested in Xcode 16.0b1), even in Swift 5 language mode. But yes, I'm also getting an error with Swift 5.10.

// This works with the Swift 6.0 compiler
protocol P1 {
    associatedtype T1
}

protocol P2: P1 where T1 == T2 {
    associatedtype T2
}

class C2: P2 {
    typealias T2 = Int
}

C2.T1.self == C2.T2.self // true
C2() is any P1 // true
C2() is any P2 // true
2 Likes