Skip to content

Commit 8944665

Browse files
authored
Merge pull request #22015 from theblixguy/fix/SR-2688
[Typechecker] allow @autoclosure closure to be a typealias
2 parents f2f4cb8 + 843539b commit 8944665

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,21 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20092009
hasFunctionAttr = true;
20102010
break;
20112011
}
2012-
2012+
2013+
// If we have an @autoclosure then try resolving the top level type repr
2014+
// first as it may be pointing to a typealias
2015+
if (attrs.has(TAK_autoclosure)) {
2016+
if (auto CITR = dyn_cast<ComponentIdentTypeRepr>(repr)) {
2017+
auto typeAliasResolver = TypeResolverContext::TypeAliasDecl;
2018+
if (auto type = resolveTopLevelIdentTypeComponent(resolution, CITR,
2019+
typeAliasResolver)) {
2020+
if (auto TAT = dyn_cast<TypeAliasType>(type.getPointer())) {
2021+
repr = TAT->getDecl()->getUnderlyingTypeLoc().getTypeRepr();
2022+
}
2023+
}
2024+
}
2025+
}
2026+
20132027
// Function attributes require a syntactic function type.
20142028
auto *fnRepr = dyn_cast<FunctionTypeRepr>(repr);
20152029

test/attr/attr_autoclosure.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,14 @@ func rdar_30906031(in arr: [Int], fn: @autoclosure () -> Int) -> Bool {
234234
arr.lazy.filter { $0 >= escapableF() }.isEmpty
235235
}
236236
}
237+
238+
// SR-2688
239+
class Foo {
240+
typealias FooClosure = () -> String
241+
func fooFunction(closure: @autoclosure FooClosure) {} // ok
242+
}
243+
244+
class Bar {
245+
typealias BarClosure = (String) -> String
246+
func barFunction(closure: @autoclosure BarClosure) {} // expected-error {{argument type of @autoclosure parameter must be '()'}}
247+
}

0 commit comments

Comments
 (0)