Skip to content

Commit 61ac13b

Browse files
authored
Merge pull request #19376 from xedin/rdar-44569159
[CSDiagnostics] Fix requirement source lookup to support subscripts
2 parents d78fb4e + 882875e commit 61ac13b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ ValueDecl *RequirementFailure::getDeclRef() const {
102102
ConstraintLocatorBuilder member(locator);
103103
locator =
104104
cs.getConstraintLocator(member.withPathElement(PathEltKind::Member));
105+
} else if (isa<SubscriptExpr>(anchor)) {
106+
ConstraintLocatorBuilder subscript(locator);
107+
locator = cs.getConstraintLocator(
108+
subscript.withPathElement(PathEltKind::SubscriptMember));
105109
}
106110

107111
auto overload = getOverloadChoiceIfAvailable(locator);

test/Constraints/rdar44569159.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {}
4+
struct S<V> where V: P { // expected-note {{where 'V' = 'Double'}}
5+
var value: V
6+
}
7+
8+
struct A {
9+
subscript<T>(_ v: S<T>) -> A { // expected-note {{where 'T' = 'Double'}}
10+
fatalError()
11+
}
12+
}
13+
14+
func foo(_ v: Double) {
15+
_ = A()[S(value: v)]
16+
// expected-error@-1 {{subscript 'subscript' requires that 'Double' conform to 'P'}}
17+
// expected-error@-2 {{referencing initializer 'init(value:)' on 'S' requires that 'Double' conform to 'P'}}
18+
}

0 commit comments

Comments
 (0)