Skip to content

[SymbolGraphGen] check implicit clang decls for having extension parents #83143

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

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://151911998

This PR addresses an uncommon situation in the symbol graph when importing Objective-C symbols into Swift. When a class conforms to a protocol that includes an initializer, that initializer is automatically generated for that class in the AST. This initializer has the same USR as the original protocol symbol, but is housed in a different DeclContext to indicate the membership.

Right now, we catch this situation when the protocol conformance is declared on the class definition: There's a branch to check for "implicit" decls with an underlying Clang symbol, and creates a synthesized USR if that symbols DeclContext points to a type. However, when the protocol conformance is added in a category extension, the DeclContext for the generated initializer points to the extension, causing the symbol to bypass that check and get added to the symbol graph with a duplicated USR. This PR adds a check to look for ExtensionDecls as the DeclContext so that the symbol can correctly receive a synthesized USR.

One of the tests in this PR (SymbolGraph/ClangImporter/ObjCInitializer.swift) tests a similar situation where this "implicit decl with a Clang node" is created: Some initializers in Objective-C get imported into Swift twice, with differently-adapted parameter names. This is covered by the original code, but i wanted to leave the test in because i broke this case in my initial investigation! 😅 The other test (SymbolGraph/ClangImporter/ProtocolInitializer.swift) tests the new behavior that is fixed by this PR.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link

@snprajwal snprajwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the fix!

@QuietMisdreavus QuietMisdreavus merged commit 235f140 into swiftlang:main Jul 18, 2025
3 checks passed
@QuietMisdreavus QuietMisdreavus deleted the misplaced-synthesis branch July 18, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants