Skip to content

Commit e3ff1dd

Browse files
authored
Merge pull request #71529 from xedin/copyable-cs-issues
[CSRanking] Adjust `isDeclMoreConstrainedThan` to account for inverti…
2 parents 74a3839 + 218346c commit e3ff1dd

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,16 @@ static bool isDeclMoreConstrainedThan(ValueDecl *decl1, ValueDecl *decl2) {
344344
for (size_t i = 0; i < params1.size(); i++) {
345345
auto p1 = params1[i];
346346
auto p2 = params2[i];
347-
348-
int np1 = static_cast<int>(sig1->getRequiredProtocols(p1).size());
349-
int np2 = static_cast<int>(sig2->getRequiredProtocols(p2).size());
347+
348+
int np1 =
349+
llvm::count_if(sig1->getRequiredProtocols(p1), [](const auto *P) {
350+
return !P->getInvertibleProtocolKind();
351+
});
352+
int np2 =
353+
llvm::count_if(sig2->getRequiredProtocols(p2), [](const auto *P) {
354+
return !P->getInvertibleProtocolKind();
355+
});
356+
350357
int aDelta = np1 - np2;
351358

352359
if (aDelta)

test/Constraints/overload.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,23 @@ func fn63834_3() -> String {} // expected-note {{found candidate with type 'Stri
329329
func fn63834_3() -> Double {} // expected-note {{found candidate with type 'Double'}}
330330

331331
fn63834_3() as Int // expected-error {{no exact matches in call to global function 'fn63834_3'}}
332+
333+
// Make sure that Copyable and/or Escapable don't change overloading behavior
334+
do {
335+
struct S {
336+
var v: Int
337+
}
338+
339+
func test(data: [S]) {
340+
let transformed = data.flatMap { e in
341+
if true {
342+
return Array<S>()
343+
}
344+
return Array(arrayLiteral: e)
345+
}
346+
347+
_ = transformed.map {
348+
_ = $0.v // Ok
349+
}
350+
}
351+
}

0 commit comments

Comments
 (0)