File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -3950,8 +3950,20 @@ generateForEachStmtConstraints(
3950
3950
forEachStmtInfo.makeIteratorVar = PB;
3951
3951
3952
3952
// Type of sequence expression has to conform to Sequence protocol.
3953
+ //
3954
+ // Note that the following emulates having `$generator` separately
3955
+ // type-checked by introducing a `TVO_PrefersSubtypeBinding` type
3956
+ // variable that would make sure that result of `.makeIterator` would
3957
+ // get ranked standalone.
3953
3958
{
3954
- cs.addConstraint (ConstraintKind::ConformsTo, cs.getType (sequenceExpr),
3959
+ auto *externalIteratorType = cs.createTypeVariable (
3960
+ cs.getConstraintLocator (sequenceExpr), TVO_PrefersSubtypeBinding);
3961
+
3962
+ cs.addConstraint (ConstraintKind::Equal, externalIteratorType,
3963
+ cs.getType (sequenceExpr),
3964
+ externalIteratorType->getImpl ().getLocator ());
3965
+
3966
+ cs.addConstraint (ConstraintKind::ConformsTo, externalIteratorType,
3955
3967
sequenceProto->getDeclaredInterfaceType (),
3956
3968
contextualLocator);
3957
3969
Original file line number Diff line number Diff line change @@ -245,3 +245,8 @@ func testForEachWhereWithClosure(_ x: [Int]) {
245
245
for i in x where x. contains ( where: { $0. byteSwapped == i } ) { }
246
246
}
247
247
248
+ // https://github.com/apple/swift/issues/59522 - use of `prefix` with generic base causes ambiguity in for-in statement
249
+ func test_no_ambiguity_with_prefix_iterator< C: Collection > ( c: C ) {
250
+ for _ in c. prefix ( 1 ) { // Ok
251
+ }
252
+ }
You can’t perform that action at this time.
0 commit comments