Skip to content

Commit c2a93f0

Browse files
committed
[interop][SwiftToCxx] allow emission of overloaded functions with the same name
1 parent 62c1f4a commit c2a93f0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ class ModuleWriter {
661661
int result = getSortName(*rhs).compare(getSortName(*lhs));
662662
if (result != 0)
663663
return result;
664+
// Two overloaded functions can have the same name when emitting C++.
665+
if (isa<AbstractFunctionDecl>(*rhs) && isa<AbstractFunctionDecl>(*lhs))
666+
return result;
664667

665668
// Prefer value decls to extensions.
666669
assert(!(isa<ValueDecl>(*lhs) && isa<ValueDecl>(*rhs)));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -clang-header-expose-decls=all-public -emit-clang-header-path %t/functions.h
3+
// RUN: %FileCheck %s < %t/functions.h
4+
5+
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
6+
7+
8+
9+
public func overloadedFunc(_ x: Int) { }
10+
public func overloadedFunc(_ y: Float) { }
11+
12+
public func overloadedFuncArgLabel(x _: Int) { }
13+
public func overloadedFuncArgLabel(y _: Float) { }
14+
15+
// CHECK-DAG: void overloadedFunc(float y) noexcept
16+
// CHECK-DAG: void overloadedFunc(swift::Int x) noexcept
17+
// CHECK-DAG: void overloadedFuncArgLabel(float _1) noexcept
18+
// CHECK-DAG: void overloadedFuncArgLabel(swift::Int _1) noexcept

0 commit comments

Comments
 (0)