Skip to content

Commit 6665b56

Browse files
committed
swift-module-digester: changing open class members to public can be source-breaking.
1 parent 0afafd1 commit 6665b56

File tree

8 files changed

+25
-2
lines changed

8 files changed

+25
-2
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ ERROR(optional_req_changed,none,"%0 is %select{now|no longer}1 an optional requi
7878

7979
ERROR(var_let_changed,none,"%0 changes from %select{var|let}1 to %select{let|var}1", (StringRef, bool))
8080

81+
ERROR(no_longer_open,none,"%0 is no longer open for subclassing", (StringRef))
82+
8183
#ifndef DIAG_NO_UNDEF
8284
# if defined(DIAG)
8385
# undef DIAG

test/api-digester/Inputs/cake1.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ public protocol ObjCProtocol {
114114

115115
public let GlobalLetChangedToVar = 1
116116
public var GlobalVarChangedToLet = 1
117+
118+
public class ClassWithOpenMember {
119+
open class func foo() {}
120+
open var property: Int {get { return 1}}
121+
open func bar() {}
122+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ public protocol ObjCProtocol {
123123
}
124124

125125
public var GlobalLetChangedToVar = 1
126-
public let GlobalVarChangedToLet = 1
126+
public let GlobalVarChangedToLet = 1
127+
128+
public class ClassWithOpenMember {
129+
public class func foo() {}
130+
public var property: Int {get { return 1}}
131+
public func bar() {}
132+
}

test/api-digester/Outputs/Cake.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
5454
cake1: Class C4 has changed its super class from OldType to NewType
5555
cake1: Class SubGenericClass has changed its super class from GenericClass<P1> to GenericClass<P2>
5656
cake1: Class SuperClassRemoval has removed its super class C3
57+
cake1: Func ClassWithOpenMember.bar() is no longer open for subclassing
58+
cake1: Func ClassWithOpenMember.foo() is no longer open for subclassing
59+
cake1: Var ClassWithOpenMember.property is no longer open for subclassing

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ bool SDKNode::operator==(const SDKNode &Other) const {
690690
return false;
691691
if (Left->getGenericSignature() != Right->getGenericSignature())
692692
return false;
693-
693+
if (Left->isOpen() != Right->isOpen())
694+
return false;
694695
LLVM_FALLTHROUGH;
695696
}
696697
case SDKNodeKind::Root: {

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class SDKNodeDecl: public SDKNode {
318318
bool isStatic() const { return IsStatic; };
319319
bool isOverriding() const { return IsOverriding; };
320320
bool isOptional() const { return hasDeclAttribute(DeclAttrKind::DAK_Optional); }
321+
bool isOpen() const { return IsOpen; }
321322
StringRef getGenericSignature() const { return GenericSig; }
322323
StringRef getScreenInfo() const;
323324
virtual void jsonize(json::Output &Out) override;

tools/swift-api-digester/ModuleDiagsConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static StringRef getCategoryName(uint32_t ID) {
6363
return "/* Protocol Requirement Change */";
6464
case LocalDiagID::super_class_removed:
6565
case LocalDiagID::super_class_changed:
66+
case LocalDiagID::no_longer_open:
6667
return "/* Class Inheritance Change */";
6768
default:
6869
return StringRef();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ static void detectDeclChange(NodePtr L, NodePtr R, SDKContext &Ctx) {
727727
auto &Diags = Ctx.getDiags();
728728
if (auto LD = dyn_cast<SDKNodeDecl>(L)) {
729729
auto *RD = R->getAs<SDKNodeDecl>();
730+
if (!Ctx.checkingABI() && LD->isOpen() && !RD->isOpen()) {
731+
Diags.diagnose(SourceLoc(), diag::no_longer_open, LD->getScreenInfo());
732+
}
730733

731734
// Diagnose static attribute change.
732735
if (LD->isStatic() ^ RD->isStatic()) {

0 commit comments

Comments
 (0)