Skip to content

[CS] Don't favor based on tuple element types #40083

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
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
5 changes: 2 additions & 3 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,9 @@ namespace {
return { false, expr };
}

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

Expand Down
15 changes: 15 additions & 0 deletions test/Constraints/ranking_ambiguities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ struct S4 {
_ = S4() // expected-error {{ambiguous use of 'init'}}
}
}

infix operator ^^^
func ^^^ (lhs: (Int, Int), rhs: Int) -> Int { 0 } // expected-note {{found this candidate}}
func ^^^ (lhs: (Int, Int), rhs: Int) -> String { "" } // expected-note {{found this candidate}}

// We shouldn't favor based on the type of a tuple element.
struct S5 {
init(_ x: Int) {}
init(_ x: String) {}

func testFavoring() {
let x = 0
_ = S5((x, 0) ^^^ 0) // expected-error {{ambiguous use of operator '^^^'}}
}
}