swift
235f140b - [SymbolGraphGen] check implicit clang decls for having extension parents (#83143)

Commit
206 days ago
[SymbolGraphGen] check implicit clang decls for having extension parents (#83143) 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.
Parents
Loading