[SymbolGraphGen] check implicit clang decls for having extension parents #83143
+68
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.