Skip to content

[SR-12096] Index missing references to initializers in Result extensions #54532

@kastiglione

Description

@kastiglione
Previous ID SR-12096
Radar rdar://problem/58997223
Original Reporter @kastiglione
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 1ee7c9ff01d3a11c55b26c435d413b5a

relates to:

Issue Description:

In a specific case, the index is missing references to initializers added in an enum extension. In this case, Result.

This example is two parts. First, an extension on Result that adds initializers:

extension Result {
    public init(value: Success) {
        self = .success(value)
    }

    public init(error: Failure) {
        self = .failure(error)
    }
}

The second part is calling these initializers with explicit types:

let value = Result<Int, SomeError>(value: 5)
let error = Result<Int, SomeError>(error: .mistake)

In this case, the index does not contain a reference to the initializers. This can be seen in Xcode, where searching for references to those initializers produce only the initializers themselves.

This problem only happens when the generic types are explicit. If they're inferred, then the index does correctly include proper references. Compare:

let value: Result<Int, SomeError> = Result(value: 5)
let error: Result<Int, SomeError> = Result(error: .mistake)

In this case, the index works as expected.

In the problem case, the indexstore record files of the callers does not contain references to the initializer's symbol (USR).

Attached is a sample project, and a couple screenshots showing Xcode can't find references even though they exist in the test target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    call expressionsFeature → expressions: Call expressionsdeclarationsFeature: declarationsexpressionsFeature: expressionsgenericsFeature: generic declarations and typesindexingArea → source tooling: AST indexinginitFeature → declarations: Initializerssource toolingArea: IDE support, SourceKit, and other source toolingswift 5.8unexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions