Skip to content

Index data (SourceKit and Indexstore) for an extension of a typealias does not reference the typealias #67444

Open
@dylansturg

Description

@dylansturg

Description
When Swift code extends a typealias, the index data (either from SourceKit using its index request or the indexstore from index while building) contains no reference to the typealias. Instead it only references the real type that the typealias is alias-ing.

Consider this code:

Module Foo:

typealias ExtendableFoo = Foo

Module Bar:

extension ExtendableFoo { ... }

The index for Bar contains a reference to the type Foo, with no reference to the typealias ExtendableFoo.

Steps to reproduce

Create 2 Swift files, to be built as 2 separate Swift modules:

File Typealias.swift

public struct MyType {}
public typealias AliasType = MyType

File Extension.swift

import Typealias
extension AliasType {
	func foo() {}
}

Build a swiftmodule for Typealias.swift:

$ swiftc \
  -sdk /var/db/xcode_select_link//Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
  -target x86_64-apple-ios15.0-simulator \
  -emit-module-path .build/Typealias.swiftmodule \
  Typealias.swift

Run sourcekitd-test to index Extension.swift:

$ sourcekitd-test -req index Extension.swift -- \
  -target x86_64-apple-ios15.0-simulator \
  -sdk /var/db/xcode_select_link/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
  -F/var/db/xcode_select_link/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks \
  -F/var/db/xcode_select_link/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/Frameworks \
  -I/var/db/xcode_select_link/Platforms/iPhoneSimulator.platform/Developer/usr/lib \
  -I$(pwd)/.build -module-name Extension \
  Extension.swift 

Observe the entities results in the index data:

key.entities: [
    {
      key.kind: source.lang.swift.ref.module,
      key.name: "Typealias",
      key.usr: "c:@M@Typealias",
      key.line: 1,
      key.column: 8
    },
    {
      key.kind: source.lang.swift.decl.extension.struct,
      key.name: "MyType",
      key.usr: "s:e:s:9Typealias6MyTypeV9ExtensionE3fooyyF",
      key.line: 2,
      key.column: 11,
      key.entities: [
        {
          key.kind: source.lang.swift.ref.struct,
          key.name: "MyType",
          key.usr: "s:9Typealias6MyTypeV",
          key.line: 2,
          key.column: 11
        },
        {
          key.kind: source.lang.swift.decl.function.method.instance,
          key.name: "foo()",
          key.usr: "s:9Typealias6MyTypeV9ExtensionE3fooyyF",
          key.line: 3,
          key.column: 7,
          key.effective_access: source.decl.effective_access.internal
        }
      ]
    }
  ]

Expected behavior

I expect to see a reference to the typealias that is being extend, e.g. AliasType in this case.

Environment

  • Swift compiler version info Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
  • Xcode version info Xcode 14.3 Build version 14E222b
  • Deployment target: iOS 15.0

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 indexingmultiple modulesFlag: An issue whose reproduction requires multiple modulessource toolingArea: IDE support, SourceKit, and other source toolingswift 5.8typealiasFeature → type declarations: `typealias` declarationsunexpected 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