Skip to content

Commit a410f20

Browse files
authored
swift-api-digester: Avoid considering a type decl is removed if a typealias with the same name is simultaneously added. rdar://33307864 (swiftlang#11016)
1 parent 994121e commit a410f20

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

test/api-digester/Outputs/Cake.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
/* Removed Decls */
3-
Class C3 has been removed
43
Constructor Somestruct2.init(_:) has been removed
54
Func C4.foo() has been removed
65

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,7 @@ class DiagnosisEmitter : public SDKNodeVisitor {
26432643
void visitDecl(SDKNodeDecl *D);
26442644
void visit(NodePtr Node) override;
26452645
SDKNodeDecl *findAddedDecl(const SDKNodeDecl *Node);
2646+
bool findTypeAliasDecl(const SDKNodeDecl *Node);
26462647
static StringRef printName(StringRef Name);
26472648
static StringRef printDiagKeyword(StringRef Name);
26482649
static void collectAddedDecls(NodePtr Root, std::set<SDKNodeDecl*> &Results);
@@ -2766,6 +2767,16 @@ SDKNodeDecl *DiagnosisEmitter::findAddedDecl(const SDKNodeDecl *Root) {
27662767
return nullptr;
27672768
}
27682769

2770+
bool DiagnosisEmitter::findTypeAliasDecl(const SDKNodeDecl *Node) {
2771+
if (Node->getKind() != SDKNodeKind::TypeDecl)
2772+
return false;
2773+
return std::any_of(AddedDecls.begin(), AddedDecls.end(),
2774+
[&](SDKNodeDecl *Added) {
2775+
return Added->getKind() == SDKNodeKind::TypeAlias &&
2776+
Added->getPrintedName() == Node->getPrintedName();
2777+
});
2778+
}
2779+
27692780
StringRef DiagnosisEmitter::printName(StringRef Name) {
27702781
OSColor Color(llvm::outs(), llvm::raw_ostream::CYAN);
27712782
Color << Name;
@@ -2861,6 +2872,10 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
28612872
auto &Ctx = Node->getSDKContext();
28622873
switch(Anno) {
28632874
case NodeAnnotation::Removed: {
2875+
// If we can find a type alias decl with the same name of this type, we
2876+
// consider the type is not removed.
2877+
if (findTypeAliasDecl(Node))
2878+
return;
28642879
if (auto *Added = findAddedDecl(Node)) {
28652880
if (Node->getDeclKind() != DeclKind::Constructor) {
28662881
MovedDecls.Diags.emplace_back(Node->getDeclKind(),

0 commit comments

Comments
 (0)