Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13857] indexstore missing references for superclass / protocol when using composition #56255

Closed
keith opened this issue Nov 13, 2020 · 6 comments · Fixed by #64997, #65550 or #65618
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. indexing Area → source tooling: AST indexing inheritance Feature → type declarations → class: Subclassing and inheritance of class members protocol compositions Feature → types: protocol composition types source tooling Area: IDE support, SourceKit, and other source tooling swift 5.9 types Feature: types unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@keith
Copy link
Member

keith commented Nov 13, 2020

Previous ID SR-13857
Radar rdar://problem/71447059
Original Reporter @keith
Type Bug

Attachment: Download

Environment

Xcode 12.2 (12B45b)

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

md5: 3d2406440cd5302076477f42903a56d5

Issue Description:

With this code:

class ZZ1 {}
typealias BaseAlias = ZZ1 & Protocol
protocol Protocol {}

class Subclass: BaseAlias {}

The index store produced by building does not contain references from Subclass to ZZ1 as the superclass, or Protocol. This causes Xcode to not display the superclasses / protocol connections in the UI, and also impacts custom tooling built on index store data.

The difference is specifically a few symbols. With this code:

class ZZ1 {}
typealias BaseAlias = ZZ1 & Protocol
protocol Protocol {}

class Subclass: ZZ1 {}

You have this (normalized for display) reference which is missing when building the original snippet: s:10superclass3ZZ1C baseOf s:10superclass8SubclassC

If you use this code:

class ZZ1 {}
typealias BaseAlias = ZZ1
protocol Protocol {}

class Subclass: BaseAlias, Protocol {}

You end up with both the reference to the superclass, and a protocol reference: s:10superclass8ProtocolP baseOf s:10superclass8SubclassC.

Attached are the screenshots of how this ends up affecting Xcode's UI

@keith
Copy link
Member Author

keith commented Nov 13, 2020

Turns out you don't actually need the type alias here, using this code has the same issue:

class ZZ1 {}
protocol Protocol {}

class Subclass: ZZ1 & Protocol {}

@typesanitizer
Copy link

@swift-ci create

@keith
Copy link
Member Author

keith commented Nov 16, 2020

I'd be happy to take a stab at this if someone could offer some guidance!

@akyrtzi
Copy link
Contributor

akyrtzi commented Nov 18, 2020

Interesting, as you pointed out it's not the typealias the problem, it's that it uses composition. The code is in lib/Index/Index.cpp, look for references of SymbolRole::RelationBaseOf if you want to take a stab. Related tests are in test/Index.

@keith
Copy link
Member Author

keith commented Apr 7, 2023

Thanks for the tip! I got to it eventually! 🙃 #64997

@AnthonyLatsis AnthonyLatsis added source tooling Area: IDE support, SourceKit, and other source tooling inheritance Feature → type declarations → class: Subclassing and inheritance of class members protocol compositions Feature → types: protocol composition types indexing Area → source tooling: AST indexing types Feature: types swift 5.3 unexpected behavior Bug: Unexpected behavior or incorrect output labels Apr 7, 2023
keith added a commit to keith/swift that referenced this issue Apr 28, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes swiftlang#56255
keith added a commit to keith/swift that referenced this issue Apr 28, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes swiftlang#56255
keith added a commit to keith/swift that referenced this issue Apr 29, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes swiftlang#56255
keith added a commit to keith/swift that referenced this issue Apr 30, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes swiftlang#56255

(cherry picked from commit 7a5e9dc / swiftlang#64997)
@keith
Copy link
Member Author

keith commented May 1, 2023

take 2 after a revert #65550

@AnthonyLatsis AnthonyLatsis reopened this May 2, 2023
keith added a commit that referenced this issue May 3, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes #56255

This reverts commit 5e2c7a9.
keith added a commit to keith/swift that referenced this issue May 3, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes swiftlang#56255

(cherry picked from commit 6c2ccb4)
keith added a commit that referenced this issue May 30, 2023
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes #56255

(cherry picked from commit 6c2ccb4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. indexing Area → source tooling: AST indexing inheritance Feature → type declarations → class: Subclassing and inheritance of class members protocol compositions Feature → types: protocol composition types source tooling Area: IDE support, SourceKit, and other source tooling swift 5.9 types Feature: types unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
4 participants