Files
swift-mirror/test/Interop/SwiftToCxx/enums/enum-element-method-name-clash.swift
Becca Royal-Gordon da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00

37 lines
1.1 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -module-name Enums -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/enums.h
// RUN: %FileCheck %s < %t/enums.h
public enum Foo: Hashable, Sendable {
case bar(Parameters)
// We do not want to generate C++ wrappers for this function yet
// because its name clashes with the enum element above preventing
// the generated header from compilation.
public static func bar(version: Int) -> Self {
Self.bar(Parameters(version: version))
}
}
extension Foo {
public struct Parameters: Hashable, Sendable {
public var version: Int
public init(version: Int) {
self.version = version
}
}
}
// CHECK-NOT: Foo bar(swift::Int version)
// CHECK: class SWIFT_SYMBOL("s:5Enums3FooO") Foo final {
// CHECK: switch (_getEnumTag()) {
// CHECK-NEXT: case 0: return cases::bar;
// CHECK-NEXT: default: abort();
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-EMPTY:
// Before the fix, we had the static method's thunk here.
// CHECK-NEXT: swift::Int getHashValue() const