Skip to content

Commit 61f3542

Browse files
committed
[CSSimplify] Report unresolved base failure if leading-dot syntax base is a placeholder
If base type of the leading-dot syntax expression has been determined to be a placeholder, this could only mean that `.<name>` couldn't be resolved in the current context. Resolves: rdar://104302974 (cherry picked from commit 9308796)
1 parent 9b80c1a commit 61f3542

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6158,6 +6158,17 @@ bool ConstraintSystem::repairFailures(
61586158
if (rhs->isPlaceholder())
61596159
return true;
61606160

6161+
// The base is a placeholder, let's report an unknown base issue.
6162+
if (lhs->isPlaceholder()) {
6163+
auto *baseExpr =
6164+
castToExpr<UnresolvedMemberChainResultExpr>(anchor)->getChainBase();
6165+
6166+
auto *fix = SpecifyBaseTypeForContextualMember::create(
6167+
*this, baseExpr->getName(), getConstraintLocator(locator));
6168+
conversionsOrFixes.push_back(fix);
6169+
break;
6170+
}
6171+
61616172
if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
61626173
locator))
61636174
break;

test/Constraints/members.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,3 +794,11 @@ func test_diagnose_inaccessible_member_in_ambiguous_context() {
794794

795795
test(\.x) // expected-error {{'x' is inaccessible due to 'private' protection level}}
796796
}
797+
798+
// rdar://104302974
799+
func test_leading_dot_syntax_unknown_base_ambiguity() {
800+
func fn<S: StringProtocol, T: Hashable>(_: S, value: T?) {}
801+
func fn<T: Hashable>(_: String, value: T?) {}
802+
803+
fn("", value: .member) // expected-error {{cannot infer contextual base in reference to member 'member'}}
804+
}

0 commit comments

Comments
 (0)