Skip to content

Commit 6c5186f

Browse files
committed
[CSFix] Diagnose missing base type unwrap in ambiguous contexts
1 parent 4f2a175 commit 6c5186f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/swift/Sema/CSFix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ class UnwrapOptionalBase final : public ConstraintFix {
529529

530530
bool diagnose(const Solution &solution, bool asNote = false) const override;
531531

532+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
533+
return diagnose(*commonFixes.front().first);
534+
}
535+
532536
static UnwrapOptionalBase *create(ConstraintSystem &cs, DeclNameRef member,
533537
Type memberBaseType,
534538
ConstraintLocator *locator);

test/expr/unary/keypath/keypath.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,8 @@ func f_56996() {
10671067
// https://github.com/apple/swift/issues/55805
10681068
// Key-path missing optional crashes compiler: Inactive constraints left over?
10691069
func f_55805() {
1070-
let _: KeyPath<String?, Int?> = \.utf8.count // expected-error {{no exact matches in reference to property 'count'}}
1071-
// expected-note@-1 {{found candidate with type 'Int'}}
1070+
let _: KeyPath<String?, Int?> = \.utf8.count // expected-error {{value of optional type 'String.UTF8View?' must be unwrapped to refer to member 'count' of wrapped base type 'String.UTF8View'}}
1071+
// expected-note@-1 {{chain the optional using '?' to access member 'count' only for non-'nil' base values}}
10721072
}
10731073

10741074
// rdar://74711236 - crash due to incorrect member access in key path

0 commit comments

Comments
 (0)