mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
C++ namespaces are module-independent, but enums are owned by their module's in Swift. So, to prevent declaring two enums with the same name, this patch implements a new approach to namespaces: enums with extensions.
Here's an example:
```
// Module A
namespace N { void test1(); }
// Module B
namespace N { void test2(); }
// __ObjC module
enum N { }
// Swift module A
extension N { func test1() }
// Swift module B
extension N { func test1() }
```
Thanks to @gribozavr for the great idea.
35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
// RUN: %target-swift-ide-test -print-module -module-to-print=Classes -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
|
|
|
|
// CHECK-NOT: extension
|
|
// CHECK: extension ClassesNS1.ClassesNS2 {
|
|
// CHECK: struct BasicStruct {
|
|
// CHECK: init()
|
|
// CHECK: mutating func basicMember() -> UnsafePointer<CChar>!
|
|
// CHECK: }
|
|
// CHECK: struct ForwardDeclaredStruct {
|
|
// CHECK: init()
|
|
// CHECK: mutating func basicMember() -> UnsafePointer<CChar>!
|
|
// CHECK: }
|
|
// CHECK: }
|
|
// CHECK-NOT: extension
|
|
|
|
// CHECK: extension ClassesNS1 {
|
|
// CHECK: struct BasicStruct {
|
|
// CHECK: init()
|
|
// CHECK: mutating func basicMember() -> UnsafePointer<CChar>!
|
|
// CHECK: }
|
|
// CHECK: struct ForwardDeclaredStruct {
|
|
// CHECK: init()
|
|
// CHECK: mutating func basicMember() -> UnsafePointer<CChar>!
|
|
// CHECK: }
|
|
// CHECK: }
|
|
// CHECK-NOT: extension
|
|
|
|
// CHECK: extension ClassesNS3 {
|
|
// CHECK: struct BasicStruct {
|
|
// CHECK: init()
|
|
// CHECK: mutating func basicMember() -> UnsafePointer<CChar>!
|
|
// CHECK: }
|
|
// CHECK: }
|
|
// CHECK-NOT: extension
|