SE-0299 Extending Static Member Lookup in Generic Contexts

Could you clarify why this is a language feature rather than, say, a SourceKit feature? Say something along the lines of:

  1. You type a leading dot at an argument position where the type is generic.
  2. If there are no protocol requirements, SourceKit does nothing.
  3. If there are protocol requirements, SourceKit looks up which types are declared to conform to protocol requirements and pass on the list to the editor for completion.
  4. When a completion is chosen, the editor deletes the previous dot and inserts the selected type.

I'm reading through the comments here and re-reading the proposal, and it seems like all of the discussion is focused on describing how we could make this work as a language feature. As I understand it, the primary benefit is in helping someone write code [speaking as someone who just started learning SwiftUI last week and hit this issue of "wait what do I put here???"], and the benefit for readability is not that big (IMO).

Implementing this as a SourceKit feature has three benefits:

  1. We don't need to change the language. If people still feel that this really impairs readability, then we can revisit the issue at a later stage.
  2. It avoids the weird edge cases that other people have pointed out, such as this one.
    func squared<T: FixedWidthInteger>(_ x: T) -> T? { ... }
    let squaredBitWidth = squared(.bitWidth) // picks T == Int
    
  3. Library maintainers don't have the additional burden of such similar static members for protocols they are vending.
6 Likes