Skip to content

[5.1][ConstraintSystem] Shrink: If root expression is assignment always co… #25753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,12 @@ void ConstraintSystem::shrink(Expr *expr) {
return expr;
}

// Or it's a function application with other candidates present.
if (isa<ApplyExpr>(expr)) {
// Or it's a function application or assignment with other candidates
// present. Assignment should be easy to solve because we'd get a
// contextual type from the destination expression, otherwise shrink
// might produce incorrect results without considering aforementioned
// destination type.
if (isa<ApplyExpr>(expr) || isa<AssignExpr>(expr)) {
Candidates.push_back(Candidate(CS, PrimaryExpr));
return expr;
}
Expand Down
23 changes: 23 additions & 0 deletions test/Constraints/generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,26 @@ func test_generic_subscript_with_missing_arg() {
_ = s[0] // expected-error {{generic parameter 'U' could not be inferred}}
}
}

// rdar://problem/51413254

infix operator ==>

struct Key {
init(_ key: String) {}
}

func ==> (lhs: Any, rhs: Key) throws -> Any {
return 0
}

func ==> <A>(lhs: Any, rhs: Key) throws -> A {
fatalError()
}

struct R_51413254 {
var str: String = ""
mutating func test(_ anyDict: Any) throws {
self.str = try anyDict ==> Key("a") // Ok
}
}