Skip to content

Commit 6449e47

Browse files
authored
Merge pull request #22231 from theblixguy/fix/SR-9760
[Typechecker] Fix an issue with @escaping when used with a generic function
2 parents aa4d406 + be6dc7c commit 6449e47

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,13 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
21622162
if (!ty) ty = resolveType(repr, instanceOptions);
21632163
if (!ty || ty->hasError()) return ty;
21642164

2165+
// Type aliases inside protocols are not yet resolved in the structural
2166+
// stage of type resolution
2167+
if (ty->is<DependentMemberType>() &&
2168+
resolution.getStage() == TypeResolutionStage::Structural) {
2169+
return ty;
2170+
}
2171+
21652172
// Handle @escaping
21662173
if (hasFunctionAttr && ty->is<FunctionType>()) {
21672174
if (attrs.has(TAK_escaping)) {

test/attr/attr_escaping.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,16 @@ class HasIVarCaptures {
217217
})()
218218
}
219219
}
220+
221+
// https://bugs.swift.org/browse/SR-9760
222+
protocol SR_9760 {
223+
typealias F = () -> Void
224+
typealias G<T> = (T) -> Void
225+
func foo<T>(_: T, _: @escaping F) // Ok
226+
func bar<T>(_: @escaping G<T>) // Ok
227+
}
228+
229+
extension SR_9760 {
230+
func fiz<T>(_: T, _: @escaping F) {} // Ok
231+
func baz<T>(_: @escaping G<T>) {} // Ok
232+
}

0 commit comments

Comments
 (0)