Files
swift-mirror/test/Interop/SwiftToCxx/methods/method-in-extension-in-cxx.swift
Egor Zhdan cfbdd76493 [cxx-interop] Avoid ambiguous C++ overloads for functions from Swift extensions
Reverse interop has logic that avoids emitting ambiguous overloads into the generated header. That logic did not apply for functions declared within Swift extensions. This meant that the generated C++ header would sometimes not compile.

rdar://158252800
2025-08-19 15:27:26 +01:00

23 lines
795 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -module-name Method -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/methods.h
// RUN: %FileCheck %s < %t/methods.h
// RUN: %check-interop-cxx-header-in-clang(%t/methods.h -Wno-unused-function -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
public struct OverloadedMethodInExtension {
var x: Int
public mutating func add(_ x: Int) {
self.x += x
}
}
extension OverloadedMethodInExtension {
public mutating func add(viaExtension x: Int) {
self.x += x
}
}
// Make sure we don't emit ambiguous overloads:
// CHECK: SWIFT_INLINE_THUNK void OverloadedMethodInExtension::add(swift::Int x)
// CHECK-NOT: SWIFT_INLINE_THUNK void OverloadedMethodInExtension::add(swift::Int x)