Files
swift-mirror/test/Sema/COM.swift
Saleem Abdulrasool 4ae91bec2c AST,Sema: synthesize IUnknown, ISwiftObject conformances
Add synthesis of the protocol conformances for the known protocols with
`@com`.

`ISwiftObject` may not be explicitly conformed to, it is a purely
compiler managed sealed protocol. Generate a diagnostic for the explicit
conformance.
2026-07-07 22:50:05 -07:00

86 lines
2.6 KiB
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-com-interop
@com(interface: "00000000-0000-0000-C000-000000000046")
protocol IUnknown: AnyObject { }
struct GUID {
public init(data1: UInt32, data2: UInt16, data3: UInt16,
data4: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
}
}
@com(interface: "8e369447-5188-5ada-b9ec-8fcb732d226b")
protocol ISwiftObject {
}
@com(interface: "00000000-0000-0000-0000-000000000000")
protocol IInterface1: IUnknown { }
@com(interface: "00000000-0000-0000-0000-000000000000")
protocol IInterface2: IInterface1 { }
@com(interface: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")
protocol IUpperCase: IUnknown { }
@com(interface: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
protocol ILowerCase: IUnknown { }
@com
class CClass1 { }
@com
class CClass2: IUnknown { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
class CClass3 { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
class CClass4: IUnknown { }
@com(implementation: "00000000-0000-0000-0000-000000000000", threading: .apartment)
class CClass5: IUnknown { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
class CClass6: IInterface1, IInterface2 { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
final class CClass7 { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
final class CClass8: IUnknown { }
@com(implementation: "00000000-0000-0000-0000-000000000000")
final class CClass9: IUnknown, IInterface1 { }
@com
protocol IInterface3: IUnknown { }
// expected-error@-2 {{'@com' on a protocol requires 'interface:' argument}}
@com(interface: "guid")
protocol IInterface4: IUnknown { }
// expected-error@-2 {{'guid' is not a valid GUID}}
@com(interface: "00000000-0000-0000-0000-00000000")
protocol IInterface5: IUnknown { }
// expected-error@-2 {{'00000000-0000-0000-0000-00000000' is not a valid GUID}}
@com(interface: "{00000000-0000-0000-0000-000000000000}")
protocol IInterface6: IUnknown { }
// expected-error@-2 {{'{00000000-0000-0000-0000-000000000000}' is not a valid GUID}}
@com(implementation: "00000000-0000-0000-0000-000000000000")
protocol IInterface7: IUnknown { }
// expected-error@-2 {{'@com' on a protocol requires 'interface:' argument}}
@com(interface: "00000000-0000-0000-0000-000000000000")
class CClass10 { }
// expected-error@-2 {{'@com' on a class must not have 'interface:'; use 'implementation:' instead}}
@com(implementation: "guid")
class CClass11 { }
// expected-error@-2 {{'guid' is not a valid GUID}}
@com(implementation: "")
class CClass12 { }
// expected-error@-2 {{'' is not a valid GUID}}