Skip to content

Commit

Permalink
Merge pull request #17083 from naru-jpn/fixit-dosent-confirm-to-publi…
Browse files Browse the repository at this point in the history
…c-protocol

[SR-7629] Fix wrong fixit when the type doesn't conform to a public protocol
  • Loading branch information
jrose-apple authored Jun 26, 2018
2 parents 084698d + cfbdab1 commit 55fb2e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,14 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
requiredAccess,
protoAccessScope.accessLevelForDiagnostics(),
proto->getName());
if (auto *decl = dyn_cast<AbstractFunctionDecl>(witness)) {
auto isMemberwiseInitializer =
decl->getBodyKind() ==
AbstractFunctionDecl::BodyKind::MemberwiseInitializer;
if (isMemberwiseInitializer) {
return;
}
}
auto fixItDiag = diags.diagnose(witness, diag::witness_fix_access,
witness->getDescriptiveKind(),
requiredAccess);
Expand Down
17 changes: 17 additions & 0 deletions test/attr/accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,20 @@ public struct AdoptViaCombinedProtocol : ProtoWithReqs, ReqProvider2 {
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
public typealias Assoc = Int
}

public protocol PublicInitProto {
var value: Int { get }
init(value: Int)
}
public struct NonPublicInitStruct: PublicInitProto {
public var value: Int
init(value: Int) {
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
// expected-note@-2 {{mark the initializer as 'public' to satisfy the requirement}}
self.value = value
}
}
public struct NonPublicMemberwiseInitStruct: PublicInitProto {
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
public var value: Int
}

0 comments on commit 55fb2e3

Please sign in to comment.