Skip to content

Commit 7448507

Browse files
slavapestovxedin
authored andcommitted
Sema: Fix 'for ... in ...' over a sequence of DynamicSelfType
1 parent 2ee371b commit 7448507

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,8 @@ Type simplifyTypeImpl(ConstraintSystem &cs, Type type, Fn getFixedTypeFn) {
21942194
// FIXME: It's kind of weird in general that we have to look
21952195
// through lvalue, inout and IUO types here
21962196
Type lookupBaseType = newBase->getWithoutSpecifierType();
2197+
if (auto selfType = lookupBaseType->getAs<DynamicSelfType>())
2198+
lookupBaseType = selfType->getSelfType();
21972199

21982200
if (lookupBaseType->mayHaveMembers() ||
21992201
lookupBaseType->is<DynamicSelfType>()) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,8 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
29102910
lookupOptions |= NameLookupFlags::KnownPrivate;
29112911

29122912
auto sequenceType = cs.getType(expr)->getRValueType();
2913+
if (auto *selfType = sequenceType->getAs<DynamicSelfType>())
2914+
sequenceType = selfType->getSelfType();
29132915

29142916
// Look through one level of optional; this improves recovery but doesn't
29152917
// change the result.

test/decl/func/dynamic_self.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,20 @@ func useSelfOperator() {
419419
let s = SelfOperator()
420420
_ = s + s
421421
}
422+
423+
// for ... in loops
424+
425+
struct DummyIterator : IteratorProtocol {
426+
func next() -> Int? { return nil }
427+
}
428+
429+
class Iterable : Sequence {
430+
func returnsSelf() -> Self {
431+
for _ in self {}
432+
return self
433+
}
434+
435+
func makeIterator() -> DummyIterator {
436+
return DummyIterator()
437+
}
438+
}

0 commit comments

Comments
 (0)