Index data incomplete when using `Self` to initialize a type
Closed this issue · 1 comments
keith commented
With this code:
// Module0
struct Foo {
init(bar: String) {}
}
extension Foo {
static func baz() -> Self {
Self(bar: "")
}
}
The index data does not correctly tie Self
or (bar:
in the extension function to the actual locations. This is easiest to visualize with indexutil-annotate:
// Module0
/*
struct=Foo=usr is s:7Module03FooV
v */
struct Foo {
/*
constructor=init(bar:)=usr is s:7Module03FooV3barACSS_tcfc
| parameter=bar=usr is s:7Module03FooV3barACSS_tcfcADL_SSvp
| | struct=String=usr is s:SS
v v v */
init(bar: String) {}
}
/*
struct=Foo=usr is s:7Module03FooV
extension.swiftExtensionOfStruct=Foo=usr is s:e:s:7Module03FooV3bazACyFZ
v */
extension Foo {
/*
staticMethod=baz()=usr is s:7Module03FooV3bazACyFZ
v */
static func baz() -> Self {
Self(bar: "")
}
}
If you replace Self
with the explicit type Foo
you get what I would expect:
// Module0
/*
struct=Foo=usr is s:7Module03FooV
v */
struct Foo {
/*
constructor=init(bar:)=usr is s:7Module03FooV3barACSS_tcfc
| parameter=bar=usr is s:7Module03FooV3barACSS_tcfcADL_SSvp
| | struct=String=usr is s:SS
v v v */
init(bar: String) {}
}
/*
struct=Foo=usr is s:7Module03FooV
extension.swiftExtensionOfStruct=Foo=usr is s:e:s:7Module03FooV3bazACyFZ
v */
extension Foo {
/*
staticMethod=baz()=usr is s:7Module03FooV3bazACyFZ
v */
static func baz() -> Self {
/*
struct=Foo=usr is s:7Module03FooV
constructor=init(bar:)=usr is s:7Module03FooV3barACSS_tcfc
v */
Foo(bar: "")
}
}
Steps to reproduce
Using this project: selfnoindex.zip and indexutil-annotate
:
swift build
indexutil-annotate .build/debug/index/store/ Sources/Module0/Module0.swift
Expected behavior
The index data should have valid locations for Self
and the initializer call. This also appears to affect Xcode where you cannot command+click on Self
to jump to Foo
(although maybe that's unrelated)
Environment
- Swift compiler version info 5.7.2
- Xcode version info 14.2.14C18
keith commented
Extension is unrelated:
struct Foo {
init(bar: String) {}
static func baz() -> Self {
Self(bar: "")
}
}