Skip to content

Commit 9308796

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
1 parent 4eefefa commit 9308796

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
@@ -6171,6 +6171,17 @@ bool ConstraintSystem::repairFailures(
61716171
if (rhs->isPlaceholder())
61726172
return true;
61736173

6174+
// The base is a placeholder, let's report an unknown base issue.
6175+
if (lhs->isPlaceholder()) {
6176+
auto *baseExpr =
6177+
castToExpr<UnresolvedMemberChainResultExpr>(anchor)->getChainBase();
6178+
6179+
auto *fix = SpecifyBaseTypeForContextualMember::create(
6180+
*this, baseExpr->getName(), getConstraintLocator(locator));
6181+
conversionsOrFixes.push_back(fix);
6182+
break;
6183+
}
6184+
61746185
if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
61756186
locator))
61766187
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)