Resolving name collisions between enum cases and methods

Hey!

I recently worked around an issue in reverse interop (calling Swift from C++) when the name of an enum case collided with the name of a static method: [cxx-interop] Avoid emitting methods that cause name clash by Xazax-hun · Pull Request #74250 · swiftlang/swift · GitHub

The following swift code demonstrates the problem:

public enum Foo: Hashable, Sendable {
    case bar(Parameters)

    public static func bar(version: Int) -> Self {
        Self.bar(Parameters(version: version))
    }
}

The generated C++ header for the interop will have two definitons that are colliding, because we cannot overload a variable with a function:

//Definition 1:
  inline const static struct _impl_bar {  // impl struct for case bar
    SWIFT_INLINE_THUNK constexpr operator cases() const {
      return cases::bar;
    }
    SWIFT_INLINE_THUNK Foo operator()(const Parameters& val) const;
  } bar SWIFT_SYMBOL("s:17CxxInteropProblem3FooO3baryA2C10ParametersVcACmF");

//Definition 2:
static SWIFT_INLINE_THUNK Foo bar(swift::Int version) SWIFT_SYMBOL("s:17CxxInteropProblem3FooO3bar7versionACSi_tFZ");

The question is, how to resolve actually make the static method from Swift available to C++. I think the easiest solution would be to automatically rename the function whenever a collision like that happens, and I wanted to know if people are on board with this approach or have alternative ideas.

Moreover, I was wondering what strategy should we use for renaming? We could append "Static" to the end of the method, similar to what we do with "Mutating" in certain cases.

What do you think?