Skip to content

Index data on extension varies if extension has no members #65722

Open
@keith

Description

@keith

With this code:

typealias Foo = Int

extension Foo {}

You get these index references:

/*
          typealias=Foo=s:3foo3Fooa=definition
          |     struct=Int=s:Si=reference
          v     v  */
typealias Foo = Int

/*
          typealias=Foo=s:3foo3Fooa=reference
          v  */
extension Foo {}

But when you add a function to the body of the extension you get more info on the extension definition itself:

/*
          typealias=Foo=s:3foo3Fooa=definition
          |     struct=Int=s:Si=reference
          v     v  */
typealias Foo = Int

/*
          typealias=Foo=s:3foo3Fooa=reference
          struct=Int=s:Si=reference, implicit, extendedBy
          extension.swiftExtensionOfStruct=Int=s:e:s:Si3fooE3baryyF=definition
          v  */
extension Foo {
  /*
       instanceMethod=bar()=s:Si3fooE3baryyF=definition, childOf
       v  */
  func bar() {}
}

I'm not actually sure if this matters because you do also get this correct info in the case that you're adding a protocol conformance as well:

/*
          typealias=Foo=s:3foo3Fooa=definition
          |     struct=Int=s:Si=reference
          v     v  */
typealias Foo = Int

/*
         protocol=P=s:3foo1PP=definition
         v  */
protocol P {}

/*
          typealias=Foo=s:3foo3Fooa=reference
          struct=Int=s:Si=reference, implicit, extendedBy
          extension.swiftExtensionOfStruct=Int=s:e:s:Sis:3foo1PP=definition
          |    protocol=P=s:3foo1PP=reference, baseOf
          v    v  */
extension Foo: P {}

So maybe this only hits in the case the extension is a no-op anyways, but I was surprised to see a difference here so I wanted to document it

ed3555a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.declarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsindexingArea → source tooling: AST indexingsource toolingArea: IDE support, SourceKit, and other source toolingswift 5.9unexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions