File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -2763,6 +2763,21 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
2763
2763
2764
2764
case CheckKind::Access:
2765
2765
case CheckKind::AccessOfSetter: {
2766
+ // Swift 4.2 relaxed some rules for protocol witness matching.
2767
+ //
2768
+ // This meant that it was possible for an optional protocol requirement
2769
+ // to have a witness where previously in Swift 4.1 it did not.
2770
+ //
2771
+ // Since witnesses must be as visible as the protocol, this caused a
2772
+ // source compatibility break if the witness was not sufficiently
2773
+ // visible.
2774
+ //
2775
+ // Work around this by discarding the witness if its not sufficiently
2776
+ // visible.
2777
+ if (!TC.Context .isSwiftVersionAtLeast (5 ))
2778
+ if (requirement->getAttrs ().hasAttribute <OptionalAttr>())
2779
+ return ResolveWitnessResult::Missing;
2780
+
2766
2781
// Avoid relying on the lifetime of 'this'.
2767
2782
const DeclContext *DC = this ->DC ;
2768
2783
diagnoseOrDefer (requirement, false ,
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift -enable-objc-interop -swift-version 4
2
+
3
+ @objc protocol Opt {
4
+ @objc optional func f( callback: @escaping ( ) -> ( ) )
5
+ }
6
+
7
+ class Conforms : Opt {
8
+ private func f( callback: ( ) -> ( ) ) { } // expected-note {{'f' declared here}}
9
+ }
10
+
11
+ func g( x: Conforms ) {
12
+ _ = x. f ( callback: { } ) // expected-error {{'f' is inaccessible due to 'private' protection level}}
13
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift -enable-objc-interop -swift-version 5
2
+
3
+ @objc protocol Opt {
4
+ @objc optional func f( callback: @escaping ( ) -> ( ) )
5
+ }
6
+
7
+ class Conforms : Opt {
8
+ private func f( callback: ( ) -> ( ) ) { }
9
+ // expected-error@-1 {{method 'f(callback:)' must be declared internal because it matches a requirement in internal protocol 'Opt'}}
10
+ // expected-note@-2 {{mark the instance method as 'internal' to satisfy the requirement}}
11
+ }
12
+
13
+ func g( x: Conforms ) {
14
+ _ = x. f ( callback: { } )
15
+ }
You can’t perform that action at this time.
0 commit comments