mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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.
44 lines
1.3 KiB
Swift
44 lines
1.3 KiB
Swift
// RUN: %target-swift-ide-test -print-module -module-to-print=LinkedRecords -I %S/Inputs/ -source-filename=x -enable-cxx-interop | %FileCheck %s
|
|
|
|
// CHECK: extension Space {
|
|
// CHECK: struct C {
|
|
// CHECK: struct D {
|
|
// CHECK: var B: Space.A.B
|
|
// CHECK: init(B: Space.A.B)
|
|
// CHECK: }
|
|
// CHECK: }
|
|
// CHECK: struct A {
|
|
// CHECK: struct B {
|
|
// CHECK: init(_: Int32)
|
|
// CHECK: init(_: CChar)
|
|
// CHECK: }
|
|
// CHECK: init()
|
|
// CHECK: }
|
|
// CHECK: struct E {
|
|
// CHECK: init()
|
|
// CHECK: static func test(_: UnsafePointer<Space.C>!)
|
|
// CHECK: }
|
|
// CHECK: }
|
|
|
|
// CHECK: struct M {
|
|
// CHECK: init()
|
|
// CHECK: }
|
|
// CHECK: struct F {
|
|
// CHECK: struct __Unnamed_union___Anonymous_field0 {
|
|
// CHECK: struct __Unnamed_struct_c {
|
|
// CHECK: init()
|
|
// CHECK: }
|
|
// CHECK: var c: F.__Unnamed_union___Anonymous_field0.__Unnamed_struct_c
|
|
// CHECK: var m: M
|
|
// CHECK: init()
|
|
// CHECK: init(c: F.__Unnamed_union___Anonymous_field0.__Unnamed_struct_c)
|
|
// CHECK: init(m: M)
|
|
// CHECK: }
|
|
// CHECK: var __Anonymous_field0: F.__Unnamed_union___Anonymous_field0
|
|
// CHECK: var c: F.__Unnamed_union___Anonymous_field0.__Unnamed_struct_c
|
|
// CHECK: var m: M
|
|
// CHECK: var m2: M
|
|
// CHECK: init()
|
|
// CHECK: init(_ __Anonymous_field0: F.__Unnamed_union___Anonymous_field0, m2: M)
|
|
// CHECK: }
|