Skip to content

Commit a839a9d

Browse files
authored
Merge pull request swiftlang#14463 from xedin/rdar-37160679-5.0
2 parents d1d0763 + a1f6243 commit a839a9d

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.
@@ -1888,8 +1890,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
18881890
// If the 2nd type is an autoclosure, then we don't actually want to
18891891
// treat these as parallel. The first type needs wrapping in a closure
18901892
// despite already being a function type.
1891-
if (!func1->isAutoClosure() && func2->isAutoClosure())
1893+
if (!func1->isAutoClosure() && func2->isAutoClosure()) {
1894+
increaseScore(SK_FunctionConversion);
18921895
break;
1896+
}
18931897
return matchFunctionTypes(func1, func2, kind, flags, locator);
18941898
}
18951899

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 @$S12rdar371606793fooyySiyXKF
14+
foo(a1)
15+
// CHECK: function_ref @$S12rdar371606793fooyySiycF
16+
foo(a2)
17+
// CHECK: function_ref @$S12rdar371606793baryySiyKcF
18+
bar(b1)
19+
// CHECK: function_ref @$S12rdar371606793baryySiycF
20+
bar(b2)
21+
}

0 commit comments

Comments
 (0)