Skip to content

[5.9][interop][SwiftToCxx] do not assert when emitting a public var and fu… #65497

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
7 changes: 7 additions & 0 deletions lib/PrintAsClang/ModuleContentsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ class ModuleWriter {
// Two overloaded functions can have the same name when emitting C++.
if (isa<AbstractFunctionDecl>(*rhs) && isa<AbstractFunctionDecl>(*lhs))
return result;
// A function and a global variable can have the same name in C++,
// even when the variable might not actually be emitted by the emitter.
// In that case, order the function before the variable.
if (isa<AbstractFunctionDecl>(*rhs) && isa<VarDecl>(*lhs))
return 1;
if (isa<AbstractFunctionDecl>(*lhs) && isa<VarDecl>(*rhs))
return -1;

// Prefer value decls to extensions.
assert(!(isa<ValueDecl>(*lhs) && isa<ValueDecl>(*rhs)));
Expand Down
5 changes: 5 additions & 0 deletions test/Interop/SwiftToCxx/functions/swift-functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ public func passVoidReturnVoid() { print("passVoidReturnVoid") }
// CHECK: SWIFT_INLINE_THUNK void passVoidReturnVoid() noexcept SWIFT_SYMBOL("s:9Functions014passVoidReturnC0yyF") {
// CHECK: return _impl::$s9Functions014passVoidReturnC0yyF();
// CHECK: }

// CHECK: SWIFT_INLINE_THUNK void varFunctionSameName
public func varFunctionSameName(_ x: CInt) {}

public var varFunctionSameName: CInt = 0