Skip to content

[Concurrency] Disallow 'async' and non-async overloading. #34940

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
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
6 changes: 1 addition & 5 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,10 @@ struct OverloadSignature {
/// Whether this declaration has an opaque return type.
unsigned HasOpaqueReturnType : 1;

/// Whether this declaration is 'async'
unsigned HasAsync : 1;

OverloadSignature()
: UnaryOperator(UnaryOperatorKind::None), IsInstanceMember(false),
IsVariable(false), IsFunction(false), InProtocolExtension(false),
InExtensionOfGenericType(false), HasOpaqueReturnType(false),
HasAsync(false) {}
InExtensionOfGenericType(false), HasOpaqueReturnType(false) { }
};

/// Determine whether two overload signatures conflict.
Expand Down
6 changes: 0 additions & 6 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2403,10 +2403,6 @@ bool swift::conflicting(const OverloadSignature& sig1,
(sig2.IsVariable && !sig1.Name.getArgumentNames().empty()));
}

// If one is asynchronous and the other is not, they can't conflict.
if (sig1.HasAsync != sig2.HasAsync)
return false;

// Note that we intentionally ignore the HasOpaqueReturnType bit here.
// For declarations that can't be overloaded by type, we want them to be
// considered conflicting independent of their type.
Expand Down Expand Up @@ -2630,8 +2626,6 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
signature.IsTypeAlias = isa<TypeAliasDecl>(this);
signature.HasOpaqueReturnType =
!signature.IsVariable && (bool)getOpaqueResultTypeDecl();
signature.HasAsync = isa<AbstractFunctionDecl>(this) &&
cast<AbstractFunctionDecl>(this)->hasAsync();

// Unary operators also include prefix/postfix.
if (auto func = dyn_cast<FuncDecl>(this)) {
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func testNonConversions() async {

// Overloading
@available(swift, deprecated: 4.0, message: "synchronous is no fun")
func overloadedSame() -> String { "synchronous" }
func overloadedSame(_: Int = 0) -> String { "synchronous" }

func overloadedSame() async -> String { "asynchronous" }

Expand Down
3 changes: 3 additions & 0 deletions test/decl/func/async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
func redecl1() async { } // expected-note{{previously declared here}}
func redecl1() async throws { } // expected-error{{invalid redeclaration of 'redecl1()'}}

func redecl2() -> String { "" } // expected-note{{previously declared here}}
func redecl2() async -> String { "" } // expected-error{{invalid redeclaration of 'redecl2()'}}

// Override checking

class Super {
Expand Down