Skip to content

[api-digester] Don't report as API breaking when an ObjC protocol gets a new optional method #20833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/api-digester/Inputs/Foo-new-version/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <Foundation.h>

@protocol ObjcProt
-(void) someFunctionFromProt;

-(void) someFunctionFromProt2;

@optional
-(void) someOptionalFunctionFromProt;
@end

@interface ClangInterface: NSObject <ObjcProt>
- (void)someFunction;
@end
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/Foo-new-version/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo {
header "foo.h"
}
1 change: 1 addition & 0 deletions test/api-digester/Outputs/Foo-diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo: Func ObjcProt.someFunctionFromProt2() has been added as a protocol requirement
8 changes: 8 additions & 0 deletions test/api-digester/compare-clang-dump.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %empty-directory(%t.module-cache)
// RUN: %api-digester -dump-sdk -module Foo -o %t.dump1.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %S/Inputs/Foo -avoid-location
// RUN: %api-digester -dump-sdk -module Foo -o %t.dump2.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %S/Inputs/Foo-new-version -avoid-location
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json -o %t.result

// RUN: %clang -E -P -x c %S/Outputs/Foo-diff.txt -o - | sed '/^\s*$/d' > %t.expected
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
// RUN: diff -u %t.expected %t.result.tmp
4 changes: 4 additions & 0 deletions tools/swift-api-digester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ StringRef SDKNodeDecl::getFullyQualifiedName() const {
return getSDKContext().buffer(OS.str());
}

bool SDKNodeDecl::isNonOptionalProtocolRequirement() const {
return isProtocolRequirement() && !hasDeclAttribute(DAK_Optional);
}

bool SDKNodeDecl::hasDeclAttribute(DeclAttrKind DAKind) const {
return std::find(DeclAttributes.begin(), DeclAttributes.end(), DAKind) !=
DeclAttributes.end();
Expand Down
1 change: 1 addition & 0 deletions tools/swift-api-digester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class SDKNodeDecl: public SDKNode {
StringRef getFullyQualifiedName() const;
bool isDeprecated() const { return IsDeprecated; };
bool isProtocolRequirement() const { return IsProtocolReq; }
bool isNonOptionalProtocolRequirement() const;
bool hasDeclAttribute(DeclAttrKind DAKind) const;
bool isImplicit() const { return IsImplicit; };
bool isStatic() const { return IsStatic; };
Expand Down
2 changes: 1 addition & 1 deletion tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
}
// Complain about added protocol requirements
if (auto *D = dyn_cast<SDKNodeDecl>(Right)) {
if (D->isProtocolRequirement()) {
if (D->isNonOptionalProtocolRequirement()) {
bool ShouldComplain = !D->isOverriding();
// We should allow added associated types with default.
if (auto ATD = dyn_cast<SDKNodeDeclAssociatedType>(D)) {
Expand Down