Skip to content

Commit 899073e

Browse files
committed
---
yaml --- r: 348853 b: refs/heads/master c: ec45b24 h: refs/heads/master i: 348851: c941876
1 parent c4cbe7f commit 899073e

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: b5a0d58dc0c8fbbc320b83e48927355a7c58663e
2+
refs/heads/master: ec45b24b630a1491b821edb6b0c625e37e9d650f
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
221221
if (!argExpr)
222222
return None;
223223

224-
ValueDecl *callee = nullptr;
224+
Optional<OverloadChoice> choice;
225225
Type rawFnType;
226226
if (auto overload = getChoiceFor(argLocator)) {
227227
// If we have resolved an overload for the callee, then use that to get the
228228
// function type and callee.
229-
callee = overload->choice.getDeclOrNull();
229+
choice = overload->choice;
230230
rawFnType = overload->openedType;
231231
} else {
232232
// If we didn't resolve an overload for the callee, we must be dealing with
@@ -249,6 +249,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
249249
// Resolve the interface type for the function. Note that this may not be a
250250
// function type, for example it could be a generic parameter.
251251
Type fnInterfaceType;
252+
auto *callee = choice ? choice->getDeclOrNull() : nullptr;
252253
if (callee && callee->hasInterfaceType()) {
253254
// If we have a callee with an interface type, we can use it. This is
254255
// preferable to resolveInterfaceType, as this will allow us to get a
@@ -261,7 +262,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
261262
fnInterfaceType = callee->getInterfaceType();
262263

263264
// Strip off the curried self parameter if necessary.
264-
if (callee->hasCurriedSelf())
265+
if (hasAppliedSelf(cs, *choice))
265266
fnInterfaceType = fnInterfaceType->castTo<AnyFunctionType>()->getResult();
266267

267268
if (auto *fn = fnInterfaceType->getAs<AnyFunctionType>()) {

trunk/lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -728,21 +728,6 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
728728
return listener.relabelArguments(actualArgNames);
729729
}
730730

731-
static bool hasAppliedSelf(ConstraintSystem &cs, const OverloadChoice &choice) {
732-
auto *decl = choice.getDeclOrNull();
733-
if (!decl)
734-
return false;
735-
736-
auto baseType = choice.getBaseType();
737-
if (baseType)
738-
baseType = cs.getFixedTypeRecursive(baseType, /*wantRValue=*/true);
739-
740-
// In most cases where we reference a declaration with a curried self
741-
// parameter, it gets dropped from the type of the reference.
742-
return decl->hasCurriedSelf() &&
743-
doesMemberRefApplyCurriedSelf(baseType, decl);
744-
}
745-
746731
/// Find the callee declaration and uncurry level for a given call
747732
/// locator.
748733
static std::tuple<ValueDecl *, bool, ArrayRef<Identifier>, bool,

trunk/lib/Sema/ConstraintSystem.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,6 +3043,22 @@ bool constraints::isAutoClosureArgument(Expr *argExpr) {
30433043
return false;
30443044
}
30453045

3046+
bool constraints::hasAppliedSelf(ConstraintSystem &cs,
3047+
const OverloadChoice &choice) {
3048+
auto *decl = choice.getDeclOrNull();
3049+
if (!decl)
3050+
return false;
3051+
3052+
auto baseType = choice.getBaseType();
3053+
if (baseType)
3054+
baseType = cs.getFixedTypeRecursive(baseType, /*wantRValue=*/true);
3055+
3056+
// In most cases where we reference a declaration with a curried self
3057+
// parameter, it gets dropped from the type of the reference.
3058+
return decl->hasCurriedSelf() &&
3059+
doesMemberRefApplyCurriedSelf(baseType, decl);
3060+
}
3061+
30463062
bool constraints::conformsToKnownProtocol(ConstraintSystem &cs, Type type,
30473063
KnownProtocolKind protocol) {
30483064
if (auto *proto = cs.TC.getProtocol(SourceLoc(), protocol))

trunk/lib/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4014,6 +4014,11 @@ Optional<Identifier> getOperatorName(Expr *expr);
40144014
// }
40154015
bool isAutoClosureArgument(Expr *argExpr);
40164016

4017+
/// Checks whether referencing the given overload choice results in the self
4018+
/// parameter being applied, meaning that it's dropped from the type of the
4019+
/// reference.
4020+
bool hasAppliedSelf(ConstraintSystem &cs, const OverloadChoice &choice);
4021+
40174022
/// Check whether type conforms to a given known protocol.
40184023
bool conformsToKnownProtocol(ConstraintSystem &cs, Type type,
40194024
KnownProtocolKind protocol);

0 commit comments

Comments
 (0)