Skip to content

Commit 6d91274

Browse files
authored
Merge pull request #14464 from xedin/rdar-37160679-4.1
[4.1][CSSolver] Increment score when performing certain function conversions
2 parents 662d5fd + 8d6f1f2 commit 6d91274

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
10891089
return SolutionKind::Error;
10901090
if (kind < ConstraintKind::Subtype)
10911091
return SolutionKind::Error;
1092+
1093+
increaseScore(SK_FunctionConversion);
10921094
}
10931095

10941096
// A non-throwing function can be a subtype of a throwing function.
@@ -1890,8 +1892,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
18901892
// If the 2nd type is an autoclosure, then we don't actually want to
18911893
// treat these as parallel. The first type needs wrapping in a closure
18921894
// despite already being a function type.
1893-
if (!func1->isAutoClosure() && func2->isAutoClosure())
1895+
if (!func1->isAutoClosure() && func2->isAutoClosure()) {
1896+
increaseScore(SK_FunctionConversion);
18941897
break;
1898+
}
18951899
return matchFunctionTypes(func1, func2, kind, flags, locator);
18961900
}
18971901

test/Constraints/rdar37160679.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
2+
3+
func foo(_ f: @autoclosure () -> Int) {}
4+
func foo(_ f: () -> Int) {}
5+
6+
func bar(_ f: () throws -> Int) {}
7+
func bar(_ f: () -> Int) {}
8+
9+
func baz(a1: @autoclosure () -> Int,
10+
a2: () -> Int,
11+
b1: () throws -> Int,
12+
b2: () -> Int) {
13+
// CHECK: function_ref @_T012rdar371606793fooySiyXKF
14+
foo(a1)
15+
// CHECK: function_ref @_T012rdar371606793fooySiycF
16+
foo(a2)
17+
// CHECK: function_ref @_T012rdar371606793barySiyKcF
18+
bar(b1)
19+
// CHECK: function_ref @_T012rdar371606793barySiycF
20+
bar(b2)
21+
}

0 commit comments

Comments
 (0)