Skip to content

Use mapSignatureFunctionType on SubscriptDecls #23457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,10 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
bool isMethod,
bool isInitializer,
unsigned curryLevels) {
if (type->hasError()) {
return type;
}

if (curryLevels == 0) {
// In an initializer, ignore optionality.
if (isInitializer) {
Expand Down Expand Up @@ -2316,7 +2320,12 @@ CanType ValueDecl::getOverloadSignatureType() const {
if (isa<VarDecl>(this)) {
defaultSignatureType = TupleType::getEmpty(getASTContext());
} else {
defaultSignatureType = getInterfaceType()->getCanonicalType();
defaultSignatureType = mapSignatureFunctionType(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter whether we map the type before or after we add the curried self param? It means that we won't strip inout from the self param but it wasn't clear to me whether addCurriedSelfType already deals with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addCurriedSelfType() does not mark the self parameter as inout even if the storage is mutating. So I guess it doesn't matter if you add it before or after.

getASTContext(), getInterfaceType(),
/*topLevelFunction=*/true,
/*isMethod=*/false,
/*isInitializer=*/false,
1)->getCanonicalType();
}

// We want to curry the default signature type with the 'self' type of the
Expand Down
10 changes: 10 additions & 0 deletions test/decl/overload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ struct Subscript3 {
subscript(x x: Int) -> String { return "" }
}

struct Subscript4 {
subscript(f: @escaping (Int) -> Int) -> Int { // expected-note{{previously declared here}}
get { return f(0) }
}

subscript(f: (Int) -> Int) -> Int { // expected-error{{invalid redeclaration of 'subscript(_:)'}}
get { return f(0) }
}
}

struct GenericSubscripts {
subscript<T>(x: T) -> Int { return 0 } // expected-note{{previously declared here}}
}
Expand Down