Skip to content

Commit be6dc7c

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[typechecker] handle typealias inside protocols when used with @escaping
1 parent 07b1905 commit be6dc7c

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
@@ -2148,6 +2148,13 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
21482148
if (!ty) ty = resolveType(repr, instanceOptions);
21492149
if (!ty || ty->hasError()) return ty;
21502150

2151+
// Type aliases inside protocols are not yet resolved in the structural
2152+
// stage of type resolution
2153+
if (ty->is<DependentMemberType>() &&
2154+
resolution.getStage() == TypeResolutionStage::Structural) {
2155+
return ty;
2156+
}
2157+
21512158
// Handle @escaping
21522159
if (hasFunctionAttr && ty->is<FunctionType>()) {
21532160
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)