Add @_disfavoredOverload attribute to affect overload resolution.

Introduce an attribute @_disfavoredOverload that can be used to state
that a particular declaration should be avoided if there is a
successful type-check for a non-@_disfavoredOverload. It's a way to
nudge overload resolution away from particular solutions.
This commit is contained in:
Doug Gregor
2019-05-14 22:03:08 -07:00
parent 54d3930ae8
commit 5aea1315cd
9 changed files with 60 additions and 0 deletions

View File

@@ -2169,6 +2169,12 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
<< boundType->getString() << " := "
<< refType->getString() << ")\n";
}
// If this overload is disfavored, note that.
if (choice.isDecl() &&
choice.getDecl()->getAttrs().hasAttribute<DisfavoredOverloadAttr>()) {
increaseScore(SK_DisfavoredOverload);
}
}
template <typename Fn>