Skip to content

Commit a5bcf13

Browse files
authored
Merge pull request #63031 from xedin/diag-inaccessible-member-in-ambiguous-context
[CSFix] Diagnose use of inaccessible members in ambiguous contexts
2 parents 881e16c + d43d2cc commit a5bcf13

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

18521852
bool diagnose(const Solution &solution, bool asNote = false) const override;
18531853

1854+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1855+
return diagnose(*commonFixes.front().first);
1856+
}
1857+
18541858
static AllowInaccessibleMember *create(ConstraintSystem &cs, Type baseType,
18551859
ValueDecl *member, DeclNameRef name,
18561860
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)