Files
swift-mirror/test/Interop/SwiftToCxx/functions/swift-function-overloads.swift
Gabor Horvath 536df9ee50 [cxx-interop] Better support overloading in reverse interop
The overloading rules in Swift and C++ are quite different. We were very
conservative, and did not emit functions in an overload set that have
the same arity. This PR relaxes this restriction by checking if the
emitted C++ types would differ.

rdar://157673175
2026-03-24 12:03:01 +00:00

26 lines
1.0 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -module-name Functions -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/functions.h
// RUN: %FileCheck %s < %t/functions.h
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
// Different arity should always work.
public func arityOverload() { }
public func arityOverload(_ x: Int) { }
// CHECK: void arityOverload() noexcept
// CHECK: void arityOverload(swift::Int x) noexcept
// Same-arity overloads with different C++ types should both be emitted.
public func overloadedFunc(_ x: Int) { }
public func overloadedFunc(_ y: Float) { }
public func overloadedFuncArgLabel(x _: Int) { }
public func overloadedFuncArgLabel(y _: Int) { }
// CHECK: void overloadedFunc(swift::Int x) noexcept
// CHECK: void overloadedFunc(float y) noexcept
// CHECK: // Unavailable in C++: Swift global function 'overloadedFuncArgLabel(y:)'. An overload with the same C++ parameter types already exists.