Skip to content

Commit 6ef96c9

Browse files
authored
Merge pull request #40083 from hamishknight/dont-favor-tuple-elements
2 parents efb3a49 + 691da86 commit 6ef96c9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ namespace {
238238
return { false, expr };
239239
}
240240

241-
// For exprs of a structural type that are not modeling argument lists,
242-
// avoid merging the type variables. (We need to allow for cases like
241+
// For exprs of a tuple, avoid favoring. (We need to allow for cases like
243242
// (Int, Int32).)
244-
if (isa<TupleExpr>(expr) && !isa<ApplyExpr>(Parent.getAsExpr())) {
243+
if (isa<TupleExpr>(expr)) {
245244
return { false, expr };
246245
}
247246

test/Constraints/ranking_ambiguities.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,18 @@ struct S4 {
5858
_ = S4() // expected-error {{ambiguous use of 'init'}}
5959
}
6060
}
61+
62+
infix operator ^^^
63+
func ^^^ (lhs: (Int, Int), rhs: Int) -> Int { 0 } // expected-note {{found this candidate}}
64+
func ^^^ (lhs: (Int, Int), rhs: Int) -> String { "" } // expected-note {{found this candidate}}
65+
66+
// We shouldn't favor based on the type of a tuple element.
67+
struct S5 {
68+
init(_ x: Int) {}
69+
init(_ x: String) {}
70+
71+
func testFavoring() {
72+
let x = 0
73+
_ = S5((x, 0) ^^^ 0) // expected-error {{ambiguous use of operator '^^^'}}
74+
}
75+
}

0 commit comments

Comments
 (0)