Skip to content

Commit 6e35290

Browse files
committed
swift-module-digester: changing super classes is API breaking.
1 parent 9db65f8 commit 6e35290

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ ERROR(protocol_req_added,none,"%0 has been added as a protocol requirement", (St
7070

7171
ERROR(super_class_removed,none,"%0 has removed its super class %1", (StringRef, StringRef))
7272

73+
ERROR(super_class_changed,none,"%0 has changed its super class from %1 to %2", (StringRef, StringRef, StringRef))
74+
7375
#ifndef DIAG_NO_UNDEF
7476
# if defined(DIAG)
7577
# undef DIAG

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ cake2: Func RequiementChanges.addedFunc() has been added as a protocol requireme
6161
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
6262

6363
/* Class Inheritance Change */
64+
cake1: Class C4 has changed its super class from OldType to NewType
6465
cake1: Class SuperClassRemoval has removed its super class C3

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ cake2: Func RequiementChanges.addedFunc() has been added as a protocol requireme
4747
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
4848

4949
/* Class Inheritance Change */
50+
cake1: Class C4 has changed its super class from OldType to NewType
5051
cake1: Class SuperClassRemoval has removed its super class C3

tools/swift-api-digester/ModuleDiagsConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static StringRef getCategoryName(uint32_t ID) {
5959
case LocalDiagID::protocol_req_added:
6060
return "/* Protocol Requirement Change */";
6161
case LocalDiagID::super_class_removed:
62+
case LocalDiagID::super_class_changed:
6263
return "/* Class Inheritance Change */";
6364
default:
6465
return StringRef();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,15 @@ static void diagnoseNominalTypeDeclChange(SDKNodeDeclType *L, SDKNodeDeclType *R
696696
}
697697
auto LSuperClass = L->getSuperClassName();
698698
auto RSuperClass = R->getSuperClassName();
699-
if (!LSuperClass.empty()) {
699+
if (!LSuperClass.empty() && LSuperClass != RSuperClass) {
700700
if (RSuperClass.empty()) {
701701
Diags.diagnose(SourceLoc(), diag::super_class_removed, L->getScreenInfo(),
702702
LSuperClass);
703+
} else {
704+
// FIXME: This will be a false positive if the new subclass is a subclass
705+
// of the old type.
706+
Diags.diagnose(SourceLoc(), diag::super_class_changed, L->getScreenInfo(),
707+
LSuperClass, RSuperClass);
703708
}
704709
}
705710
}

0 commit comments

Comments
 (0)