Skip to content

Commit d2a0757

Browse files
authored
Merge pull request #26086 from xedin/rdar-50987089
[ConstraintSystem] `trySimplifyToExpr` shouldn't rely on locator bein…
2 parents 82b4fe7 + ae5cce4 commit d2a0757

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ bool constraints::computeTupleShuffle(ArrayRef<TupleTypeElt> fromTuple,
180180
Expr *ConstraintLocatorBuilder::trySimplifyToExpr() const {
181181
SmallVector<LocatorPathElt, 4> pathBuffer;
182182
Expr *anchor = getLocatorParts(pathBuffer);
183+
// Locators are not guaranteed to have an anchor
184+
// if constraint system is used to verify generic
185+
// requirements.
186+
if (!anchor)
187+
return nullptr;
188+
183189
ArrayRef<LocatorPathElt> path = pathBuffer;
184190

185191
SourceRange range;

test/Constraints/sr10728.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
typealias T1 = Int
4+
typealias T2 = Float
5+
typealias T3 = Bool
6+
7+
protocol P {
8+
associatedtype R
9+
static var foo: (T1, (R) -> T2) { get }
10+
}
11+
12+
extension P {
13+
static func bind() -> (T1, (R) -> T3) {
14+
return (1, { _ in true })
15+
}
16+
}
17+
18+
struct S: P {
19+
typealias R = T3
20+
21+
static let foo: (T1, (R) -> T2) = bind()
22+
// expected-error@-1 {{cannot convert value of type '(T1, (S.R) -> T3)' (aka '(Int, (Bool) -> Bool)') to specified type '(T1, (S.R) -> T2)' (aka '(Int, (Bool) -> Float)')}}
23+
}

0 commit comments

Comments
 (0)