Skip to content

Commit d43d2cc

Browse files
committed
[CSFix] Diagnose use of inaccessible members in ambiguous contexts
1 parent 2adb84d commit d43d2cc

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
@@ -1847,6 +1847,10 @@ class AllowInaccessibleMember final : public AllowInvalidMemberRef {
18471847

18481848
bool diagnose(const Solution &solution, bool asNote = false) const override;
18491849

1850+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1851+
return diagnose(*commonFixes.front().first);
1852+
}
1853+
18501854
static AllowInaccessibleMember *create(ConstraintSystem &cs, Type baseType,
18511855
ValueDecl *member, DeclNameRef name,
18521856
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)