Skip to content

Commit ae66180

Browse files
authored
Merge pull request #25753 from xedin/rdar-51413254-5.1
[5.1][ConstraintSystem] Shrink: If root expression is assignment always co…
2 parents f5f6494 + 575ef3b commit ae66180

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,12 @@ void ConstraintSystem::shrink(Expr *expr) {
829829
return expr;
830830
}
831831

832-
// Or it's a function application with other candidates present.
833-
if (isa<ApplyExpr>(expr)) {
832+
// Or it's a function application or assignment with other candidates
833+
// present. Assignment should be easy to solve because we'd get a
834+
// contextual type from the destination expression, otherwise shrink
835+
// might produce incorrect results without considering aforementioned
836+
// destination type.
837+
if (isa<ApplyExpr>(expr) || isa<AssignExpr>(expr)) {
834838
Candidates.push_back(Candidate(CS, PrimaryExpr));
835839
return expr;
836840
}

test/Constraints/generics.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,26 @@ func test_generic_subscript_with_missing_arg() {
750750
_ = s[0] // expected-error {{generic parameter 'U' could not be inferred}}
751751
}
752752
}
753+
754+
// rdar://problem/51413254
755+
756+
infix operator ==>
757+
758+
struct Key {
759+
init(_ key: String) {}
760+
}
761+
762+
func ==> (lhs: Any, rhs: Key) throws -> Any {
763+
return 0
764+
}
765+
766+
func ==> <A>(lhs: Any, rhs: Key) throws -> A {
767+
fatalError()
768+
}
769+
770+
struct R_51413254 {
771+
var str: String = ""
772+
mutating func test(_ anyDict: Any) throws {
773+
self.str = try anyDict ==> Key("a") // Ok
774+
}
775+
}

0 commit comments

Comments
 (0)