Constrained extensions and auto-completion

I have a question about auto-completion in Xcode. Do the suggestions come from some part of the Swift compiler project?
If not, then please ignore the rest of this question. :-)

I have a simple generic struct type for which I create extensions constrained by the generic type parameter as follows:

struct Item<T> {}
enum A {}
enum B {}
extension Item where T == A {
    var a: String { return "a" }
extension Item where T == B {
    var b: String { return "b" }

When I try to use an Item<A>, the auto-completion will suggest both .a and .b even though the compiler will correctly let me know that I for instance cannot use .b on an Item<A> (btw. the error message really makes me happy: 'Item<A>' is not convertible to 'Item<B>'- this makes it immediately clear to the user, that an Item<B> was clearly expected in this situation. Really nicely done!)

So my question is:
Assuming that some part of the Swift open source project is responsible for the auto-complete values: Would it be feasible to only show the auto-complete suggestions that are actually valid for an instance of a concrete value, or is the current implementation some kind of a trade-off for the sake of performance?

In case it is just something that has just not been done yet, I would love to try having a look at the issue, if somebody could point me in the general direction. :slight_smile:

1 Like

Hi @Morten_Bek_Ditlevsen — this is an issue with SourceKit, which is part of Swift's tooling system. I've opened SR-9027 to track the issue. Thanks!