Skip to content

Commit d593771

Browse files
committed
[CSOptimizer] Consider choices marked as @_disfavoredOverload
These choices could be better than some other non-disfavored ones in certain situations i.e. when `async` overload is disfavored but appears in async context it's preferrable to a non-async overload choice.
1 parent dce4c7f commit d593771

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,9 @@ static ValueDecl *isViableOverloadChoice(ConstraintSystem &cs,
371371
}
372372
}
373373

374-
// If disjunction choice is unavailable or disfavored we cannot
374+
// If disjunction choice is unavailable we cannot
375375
// do anything with it.
376-
if (decl->getAttrs().hasAttribute<DisfavoredOverloadAttr>() ||
377-
cs.isDeclUnavailable(decl, locator))
376+
if (cs.isDeclUnavailable(decl, locator))
378377
return nullptr;
379378

380379
return decl;

test/Constraints/old_hack_related_ambiguities.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,14 @@ class TestFailableOnly {
360360
}
361361
}
362362
}
363+
364+
do {
365+
@_disfavoredOverload
366+
func test(over: Int, that: String = "", block: @escaping (Int) throws -> Void) async throws {}
367+
func test(over: Int, that: String = "", block: @escaping (Int) throws -> Void) throws {}
368+
func test(over: Int, other: String = "", block: @escaping (Int) throws -> Void) throws {}
369+
370+
func perform(v: Int, block: @escaping (Int) throws -> Void) async throws {
371+
try await test(over: v, block: block) // Ok
372+
}
373+
}

0 commit comments

Comments
 (0)