Skip to content

Commit bd527c1

Browse files
committed
[CSBindings] Don't consider dependent member types even if they are wrapped in optionals
Because binding producer is going to attempt to unwrap optionals and try the type, which would lead to infinite recursion because dependent member types aren't bindable. Resolves: rdar://problem/44770297
1 parent f3893f0 commit bd527c1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ Optional<Type> ConstraintSystem::checkTypeOfBinding(TypeVariableType *typeVar,
118118
return None;
119119
}
120120

121-
// Don't bind to a dependent member type.
122-
if (type->is<DependentMemberType>()) return None;
121+
// Don't bind to a dependent member type, even if it's currently
122+
// wrapped in any number of optionals, because binding producer
123+
// might unwrap and try to attempt it directly later.
124+
if (type->lookThroughAllOptionalTypes()->is<DependentMemberType>())
125+
return None;
123126

124127
// Okay, allow the binding (with the simplified type).
125128
return type;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
protocol P {
4+
associatedtype A
5+
}
6+
7+
func foo<T: P>(_: () throws -> T) -> T.A? {
8+
fatalError()
9+
}
10+
11+
_ = foo() { fatalError() } & nil

0 commit comments

Comments
 (0)