Skip to content

Commit 9b80c1a

Browse files
committed
[CSFix] Diagnose use of inaccessible members in ambiguous contexts
(cherry picked from commit d43d2cc)
1 parent 6d9ed1d commit 9b80c1a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/swift/Sema/CSFix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,10 @@ class AllowInaccessibleMember final : public AllowInvalidMemberRef {
18391839

18401840
bool diagnose(const Solution &solution, bool asNote = false) const override;
18411841

1842+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1843+
return diagnose(*commonFixes.front().first);
1844+
}
1845+
18421846
static AllowInaccessibleMember *create(ConstraintSystem &cs, Type baseType,
18431847
ValueDecl *member, DeclNameRef name,
18441848
ConstraintLocator *locator);

test/Constraints/members.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,14 @@ func rdar92358570(_ x: RDAR92358570<ClassBoundProtocol>, _ y: RDAR92358570<SomeC
783783
y.doSomething() // expected-error {{referencing instance method 'doSomething()' on 'RDAR92358570' requires that 'any SomeClassBound & ClassBoundProtocol' inherit from 'AnyObject'}}
784784
RDAR92358570<SomeClassBound & ClassBoundProtocol>.doSomethingStatically() // expected-error {{referencing static method 'doSomethingStatically()' on 'RDAR92358570' requires that 'any SomeClassBound & ClassBoundProtocol' inherit from 'AnyObject'}}
785785
}
786+
787+
func test_diagnose_inaccessible_member_in_ambiguous_context() {
788+
struct S {
789+
private var x: Int // expected-note {{'x' declared here}}
790+
}
791+
792+
func test<T>(_: KeyPath<S, T>, y: Int = 42) {}
793+
func test<T>(_: KeyPath<S, T>, x: Int = 42) {}
794+
795+
test(\.x) // expected-error {{'x' is inaccessible due to 'private' protection level}}
796+
}

0 commit comments

Comments
 (0)