Skip to content

Commit 5fbecfa

Browse files
committed
swift-module-digester: removing setter from a subscript decl is API breaking.
1 parent f72620c commit 5fbecfa

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

test/api-digester/Inputs/cake1.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,8 @@ public protocol AssociatedTypePro {
7878

7979
public class RemoveSetters {
8080
public var Value = 4
81+
public subscript(_ idx: Int) -> Int {
82+
get { return 1 }
83+
set(newValue) {}
84+
}
8185
}

test/api-digester/Inputs/cake2.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,8 @@ public protocol AssociatedTypePro {
8585

8686
public class RemoveSetters {
8787
public private(set) var Value = 4
88+
public subscript(_ idx: Int) -> Int {
89+
get { return 1 }
90+
}
8891
}
8992

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cake1: Protocol P3 has generic signature change from <τ_0_0 : P1, τ_0_0 : P2>
99
cake1: Constructor Somestruct2.init(_:) has been removed
1010
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1111
cake1: Func C4.foo() has been removed
12+
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1213
cake1: Var RemoveSetters.Value has removed its setter
1314

1415
/* Moved Decls */

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cake1: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <
99
cake1: Constructor Somestruct2.init(_:) has been removed
1010
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1111
cake1: Func C4.foo() has been removed
12+
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1213
cake1: Var RemoveSetters.Value has removed its setter
1314

1415
/* Moved Decls */

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,13 @@ bool SDKNode::operator==(const SDKNode &Other) const {
762762
LLVM_FALLTHROUGH;
763763
}
764764
case SDKNodeKind::DeclAssociatedType:
765-
case SDKNodeKind::DeclSubscript:
765+
case SDKNodeKind::DeclSubscript: {
766+
auto *Left = dyn_cast<SDKNodeDeclSubscript>(this);
767+
auto *Right = dyn_cast<SDKNodeDeclSubscript>(&Other);
768+
if (Left && Right && Left->hasSetter() != Right->hasSetter())
769+
return false;
770+
LLVM_FALLTHROUGH;
771+
}
766772
case SDKNodeKind::DeclTypeAlias: {
767773
auto Left = this->getAs<SDKNodeDecl>();
768774
auto Right = (&Other)->getAs<SDKNodeDecl>();

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,16 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
867867
break;
868868
}
869869

870-
case SDKNodeKind::DeclSubscript:
870+
case SDKNodeKind::DeclSubscript: {
871+
if (auto *LS = dyn_cast<SDKNodeDeclSubscript>(Left)) {
872+
auto *RS = cast<SDKNodeDeclSubscript>(Right);
873+
if (LS->hasSetter() && !RS->hasSetter()) {
874+
Ctx.getDiags().diagnose(SourceLoc(), diag::removed_setter,
875+
LS->getScreenInfo());
876+
}
877+
}
878+
LLVM_FALLTHROUGH;
879+
}
871880
case SDKNodeKind::DeclAssociatedType:
872881
case SDKNodeKind::DeclFunction:
873882
case SDKNodeKind::DeclSetter:

0 commit comments

Comments
 (0)