Skip to content

Commit bf39d72

Browse files
authored
Merge pull request #23457 from Jumhyn/subscript-escaping-overload
Use mapSignatureFunctionType on SubscriptDecls
2 parents a9bccef + 427bdc5 commit bf39d72

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,10 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
22262226
bool isMethod,
22272227
bool isInitializer,
22282228
unsigned curryLevels) {
2229+
if (type->hasError()) {
2230+
return type;
2231+
}
2232+
22292233
if (curryLevels == 0) {
22302234
// In an initializer, ignore optionality.
22312235
if (isInitializer) {
@@ -2316,7 +2320,12 @@ CanType ValueDecl::getOverloadSignatureType() const {
23162320
if (isa<VarDecl>(this)) {
23172321
defaultSignatureType = TupleType::getEmpty(getASTContext());
23182322
} else {
2319-
defaultSignatureType = getInterfaceType()->getCanonicalType();
2323+
defaultSignatureType = mapSignatureFunctionType(
2324+
getASTContext(), getInterfaceType(),
2325+
/*topLevelFunction=*/true,
2326+
/*isMethod=*/false,
2327+
/*isInitializer=*/false,
2328+
1)->getCanonicalType();
23202329
}
23212330

23222331
// We want to curry the default signature type with the 'self' type of the

test/decl/overload.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ struct Subscript3 {
258258
subscript(x x: Int) -> String { return "" }
259259
}
260260

261+
struct Subscript4 {
262+
subscript(f: @escaping (Int) -> Int) -> Int { // expected-note{{previously declared here}}
263+
get { return f(0) }
264+
}
265+
266+
subscript(f: (Int) -> Int) -> Int { // expected-error{{invalid redeclaration of 'subscript(_:)'}}
267+
get { return f(0) }
268+
}
269+
}
270+
261271
struct GenericSubscripts {
262272
subscript<T>(x: T) -> Int { return 0 } // expected-note{{previously declared here}}
263273
}

0 commit comments

Comments
 (0)