Skip to content

Commit 923e2fc

Browse files
authored
Merge pull request #37924 from xedin/rdar-78917861-5.5
[5.5][CSBindings] Overload variable shouldn't be delayed by its application
2 parents 693e420 + 011d299 commit 923e2fc

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,18 @@ void PotentialBindings::infer(Constraint *constraint) {
13991399
}
14001400

14011401
case ConstraintKind::ApplicableFunction:
1402-
case ConstraintKind::DynamicCallableApplicableFunction:
1402+
case ConstraintKind::DynamicCallableApplicableFunction: {
1403+
auto overloadTy = constraint->getSecondType();
1404+
// If current type variable represents an overload set
1405+
// being applied to the arguments, it can't be delayed
1406+
// by application constraints, because it doesn't
1407+
// depend on argument/result types being resolved first.
1408+
if (overloadTy->isEqual(TypeVar))
1409+
break;
1410+
1411+
LLVM_FALLTHROUGH;
1412+
}
1413+
14031414
case ConstraintKind::BindOverload: {
14041415
DelayedBy.push_back(constraint);
14051416
break;

test/Constraints/closures.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,3 +1132,34 @@ func rdar76058892() {
11321132
}
11331133
}
11341134
}
1135+
1136+
// rdar://78917861 - Invalid generic type parameter inference
1137+
1138+
func rdar78917861() {
1139+
class Cell {}
1140+
class MyCell : Cell {}
1141+
1142+
class DataCollection<D, C: Cell> {
1143+
}
1144+
1145+
class MyCollection {
1146+
typealias DataType = String
1147+
typealias CellType = MyCell
1148+
1149+
var data: DataCollection<DataType, CellType>
1150+
1151+
init() {
1152+
self.data = DataCollection<DataType, CellType>()
1153+
}
1154+
}
1155+
1156+
class Test {
1157+
let collection = MyCollection()
1158+
1159+
lazy var prop: DataCollection = {
1160+
collection.data // Ok
1161+
// Since contextual type `DataCollection` doesn't specify generic parameters they have to be inferred
1162+
// but that has to wait until the closure is resolved because types can flow both ways
1163+
}()
1164+
}
1165+
}

0 commit comments

Comments
 (0)