Skip to content

Commit 2c744b4

Browse files
committed
[Constraint solver] Remove a dubious hack introduced with SR-2505
1 parent 0ece008 commit 2c744b4

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -917,36 +917,6 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
917917
argsWithLabels.append(args.begin(), args.end());
918918
AnyFunctionType::relabelParams(argsWithLabels, argLabels);
919919

920-
// FIXME: Remove this. It's functionally identical to the real code
921-
// path below, except for some behavioral differences in solution ranking
922-
// that I don't understand.
923-
if (params.size() == 1 &&
924-
args.size() == 1 &&
925-
params[0].getLabel().empty() &&
926-
args[0].getLabel().empty() &&
927-
!params[0].getParameterFlags().isInOut() &&
928-
!args[0].getParameterFlags().isInOut() &&
929-
params[0].getPlainType()->isAny()) {
930-
auto argType = args[0].getPlainType();
931-
932-
// Disallow assignment of noescape function to parameter of type
933-
// Any. Allowing this would allow these functions to escape.
934-
if (auto *fnTy = argType->getAs<AnyFunctionType>()) {
935-
if (fnTy->isNoEscape()) {
936-
auto *loc = cs.getConstraintLocator(locator);
937-
// Allow assigned of 'no-escape' function with recorded fix.
938-
if (cs.shouldAttemptFixes()) {
939-
if (!cs.recordFix(MarkExplicitlyEscaping::create(cs, loc)))
940-
return cs.getTypeMatchSuccess();
941-
}
942-
943-
return cs.getTypeMatchFailure(locator);
944-
}
945-
}
946-
947-
return cs.getTypeMatchSuccess();
948-
}
949-
950920
// Match up the call arguments to the parameters.
951921
SmallVector<ParamBinding, 4> parameterBindings;
952922
ArgumentFailureTracker listener(cs, parameterBindings, locator);

test/Constraints/closures.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ func r20789423() {
416416

417417
}
418418

419-
// Make sure that behavior related to allowing trailing closures to match functions
420-
// with Any as a final parameter is the same after the changes made by SR-2505, namely:
421-
// that we continue to select function that does _not_ have Any as a final parameter in
422-
// presence of other possibilities.
423-
419+
// In the example below, SR-2505 started preferring C_SR_2505.test(_:) over
420+
// test(it:). Prior to Swift 5.1, we emulated the old behavior. However,
421+
// that behavior is inconsistent with the typical approach of preferring
422+
// overloads from the concrete type over one from a protocol, so we removed
423+
// the hack.
424424
protocol SR_2505_Initable { init() }
425425
struct SR_2505_II : SR_2505_Initable {}
426426

@@ -442,10 +442,9 @@ class C_SR_2505 : P_SR_2505 {
442442
}
443443

444444
func call(_ c: C_SR_2505) -> Bool {
445-
// Note: no diagnostic about capturing 'self', because this is a
446-
// non-escaping closure -- that's how we know we have selected
447-
// test(it:) and not test(_)
448-
return c.test { o in test(o) }
445+
// Note: the diagnostic about capturing 'self', indicates that we have
446+
// selected test(_) rather than test(it:)
447+
return c.test { o in test(o) } // expected-error{{call to method 'test' in closure requires explicit 'self.' to make capture semantics explicit}}
449448
}
450449
}
451450

0 commit comments

Comments
 (0)