mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
@cdecl enums are Swift enums representable in C. These enums must have an integer raw type. They can be referenced from @cdecl functions and @objc methods. @objc enums are still rejected from @cdecl functions.
43 lines
2.0 KiB
Swift
43 lines
2.0 KiB
Swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s \
|
|
// RUN: -enable-experimental-feature CDecl
|
|
|
|
// REQUIRES: swift_feature_CDecl
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
class ObjCClass: NSObject { }
|
|
|
|
@cdecl("objcClassReturn") func objcClassReturn() -> ObjCClass { fatalError() }
|
|
// expected-error @-1 {{global function cannot be marked '@cdecl' because its result type cannot be represented in C}}
|
|
// expected-note @-2 {{classes cannot be represented in C}}
|
|
|
|
@cdecl("objcClassParams") func objcClassParams(a: ObjCClass, b: ObjCClass) { }
|
|
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter 1 cannot be represented in C}}
|
|
// expected-error @-2 {{global function cannot be marked '@cdecl' because the type of the parameter 2 cannot be represented in C}}
|
|
// expected-note @-3 2 {{classes cannot be represented in C}}
|
|
|
|
@objc
|
|
protocol ObjCProtocol {}
|
|
|
|
@cdecl("objcProtocol") func objcProtocol(a: ObjCProtocol) { }
|
|
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
|
// expected-note @-2 {{protocols cannot be represented in C}}
|
|
|
|
@objc
|
|
enum ObjCEnum: Int { case A, B }
|
|
@cdecl("objcEnumUseInCDecl") func objcEnumUseInCDecl(a: ObjCEnum) { }
|
|
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
|
// expected-note @-2 {{Swift enums not marked '@cdecl' cannot be represented in C}}
|
|
|
|
/// Objective-C accepts @cdecl enums.
|
|
@cdecl("CEnum")
|
|
enum CEnum: Int { case A, B }
|
|
@_cdecl("cdeclEnumUseInObjc") func cdeclEnumUseInObjc(a: CEnum) { }
|
|
|
|
enum SwiftEnum { case A, B }
|
|
@_cdecl("swiftEnumUseInObjc") func swiftEnumUseInObjc(a: SwiftEnum) { }
|
|
// expected-error @-1 {{global function cannot be marked '@_cdecl' because the type of the parameter cannot be represented in Objective-C}}
|
|
// expected-note @-2 {{Swift enums not marked '@cdecl' or '@objc' cannot be represented in Objective-C}}
|