Skip to content

Commit 7069e5f

Browse files
authored
Merge pull request #65497 from hyp/eng/reverse-interop-5.9-assert-var-fn-name
[5.9][interop][SwiftToCxx] do not assert when emitting a public var and fu…
2 parents 8597eca + 338c558 commit 7069e5f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,13 @@ class ModuleWriter {
669669
// Two overloaded functions can have the same name when emitting C++.
670670
if (isa<AbstractFunctionDecl>(*rhs) && isa<AbstractFunctionDecl>(*lhs))
671671
return result;
672+
// A function and a global variable can have the same name in C++,
673+
// even when the variable might not actually be emitted by the emitter.
674+
// In that case, order the function before the variable.
675+
if (isa<AbstractFunctionDecl>(*rhs) && isa<VarDecl>(*lhs))
676+
return 1;
677+
if (isa<AbstractFunctionDecl>(*lhs) && isa<VarDecl>(*rhs))
678+
return -1;
672679

673680
// Prefer value decls to extensions.
674681
assert(!(isa<ValueDecl>(*lhs) && isa<ValueDecl>(*rhs)));

test/Interop/SwiftToCxx/functions/swift-functions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ public func passVoidReturnVoid() { print("passVoidReturnVoid") }
4848
// CHECK: SWIFT_INLINE_THUNK void passVoidReturnVoid() noexcept SWIFT_SYMBOL("s:9Functions014passVoidReturnC0yyF") {
4949
// CHECK: return _impl::$s9Functions014passVoidReturnC0yyF();
5050
// CHECK: }
51+
52+
// CHECK: SWIFT_INLINE_THUNK void varFunctionSameName
53+
public func varFunctionSameName(_ x: CInt) {}
54+
55+
public var varFunctionSameName: CInt = 0

0 commit comments

Comments
 (0)