mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SE-495: Make @c an official feature
This commit is contained in:
@@ -2114,9 +2114,6 @@ ERROR(cdecl_throws,none,
|
||||
ERROR(cdecl_incompatible_with_objc,none,
|
||||
"cannot apply both '@c' and '@objc' to %kindonly0",
|
||||
(const Decl *))
|
||||
ERROR(cdecl_feature_required,none,
|
||||
"'@c' requires '-enable-experimental-feature CDecl'",
|
||||
())
|
||||
|
||||
// @used and @section
|
||||
ERROR(section_empty_name,none,
|
||||
|
||||
@@ -277,6 +277,7 @@ LANGUAGE_FEATURE(LifetimeDependenceMutableAccessors, 0, "Support mutable accesso
|
||||
LANGUAGE_FEATURE(InoutLifetimeDependence, 0, "Support @_lifetime(&)")
|
||||
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
|
||||
LANGUAGE_FEATURE(ModuleSelector, 491, "Module selectors (`Module::name` syntax)")
|
||||
LANGUAGE_FEATURE(CDecl, 495, "C compatible functions and enums with @c")
|
||||
|
||||
// Swift 6
|
||||
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
|
||||
@@ -529,9 +530,6 @@ EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
|
||||
/// Allow declarations of Swift runtime symbols using @_silgen_name.
|
||||
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
|
||||
|
||||
/// Allow use of `@c`
|
||||
EXPERIMENTAL_FEATURE(CDecl, false)
|
||||
|
||||
/// Allow use of `using` declaration that control default isolation
|
||||
/// in a file scope.
|
||||
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
|
||||
|
||||
@@ -2486,12 +2486,6 @@ void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
|
||||
if (D->getAttrs().getAttribute<ObjCAttr>()) {
|
||||
diagnose(attr->getLocation(), diag::cdecl_incompatible_with_objc, D);
|
||||
}
|
||||
|
||||
// @c needs to be enabled via a feature flag.
|
||||
if (!attr->Underscored &&
|
||||
!Ctx.LangOpts.hasFeature(Feature::CDecl)) {
|
||||
diagnose(attr->getLocation(), diag::cdecl_feature_required);
|
||||
}
|
||||
}
|
||||
|
||||
void AttributeChecker::visitExposeAttr(ExposeAttr *attr) {
|
||||
|
||||
@@ -181,6 +181,7 @@ public struct Strct {
|
||||
public let transform2: ns.anonStructInNS
|
||||
}
|
||||
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
|
||||
@@ -26,7 +26,7 @@ enum NonObjCEnum: Int {
|
||||
|
||||
class Bar {
|
||||
@objc func foo(x: Foo) {}
|
||||
@objc func nonObjC(x: NonObjCEnum) {} //expected-error{{type of the parameter cannot be represented in Objective-C}} //expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@objc func nonObjC(x: NonObjCEnum) {} //expected-error{{type of the parameter cannot be represented in Objective-C}} //expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
}
|
||||
|
||||
// <rdar://problem/23681566> @objc enums with payloads rejected with no source location info
|
||||
|
||||
@@ -24,6 +24,7 @@ public class HelloWorld: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||
|
||||
@@ -11,6 +11,7 @@ import EmitClangHeaderNonmodularIncludesStressTest
|
||||
|
||||
public class Bar : Baz {}
|
||||
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||
|
||||
@@ -9,6 +9,7 @@ import EmitClangHeaderNonmodularIncludesStressTest
|
||||
|
||||
public class Bar : Baz {}
|
||||
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||
|
||||
@@ -11,6 +11,7 @@ import EmitClangHeaderNonmodularIncludesStressTest
|
||||
public class Bar : Foo {}
|
||||
|
||||
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||
|
||||
@@ -41,6 +41,13 @@
|
||||
// CHECK-NEXT: #endif
|
||||
// CHECK-NEXT: #endif
|
||||
|
||||
// CHECK: #if defined(__cplusplus)
|
||||
// CHECK-NEXT: extern "C" {
|
||||
// CHECK-NEXT: #endif
|
||||
|
||||
// CHECK: #if defined(__cplusplus)
|
||||
// CHECK-NEXT: } // extern "C"
|
||||
// CHECK-NEXT: #endif
|
||||
|
||||
// CHECK-NOT: {{[@;{}]}}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-source-import -emit-module -emit-module-doc -o %t %s -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/enums.swiftmodule -typecheck -verify -emit-objc-header-path %t/enums.h -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module
|
||||
// RUN: %FileCheck %s < %t/enums.h
|
||||
// RUN: %FileCheck %s -input-file %t/enums.h
|
||||
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t/enums.h
|
||||
// RUN: %check-in-clang %t/enums.h
|
||||
// RUN: %check-in-clang -fno-modules -Qunused-arguments %t/enums.h -include ctypes.h -include CoreFoundation.h
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-source-import -emit-module -o /dev/null -emit-module-doc-path /dev/null -module-name enums %s -emit-objc-header-path %t/enums.WMO.h -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module
|
||||
// RUN: %FileCheck %s < %t/enums.WMO.h
|
||||
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t/enums.WMO.h
|
||||
// RUN: %FileCheck %s -input-file %t/enums.WMO.h
|
||||
// RUN: %FileCheck -check-prefix=NEGATIVE %s -input-file %t/enums.WMO.h
|
||||
// RUN: %check-in-clang %t/enums.WMO.h
|
||||
// RUN: %check-in-clang -fno-modules -Qunused-arguments %t/enums.WMO.h -include ctypes.h -include CoreFoundation.h
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
// RUN: echo "{\"%s\": {\"objc-header\": \"%t/enums-supplemental.h\"}}" > %t-output-file-map.json
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %s -enable-source-import -typecheck -verify -supplementary-output-file-map %t-output-file-map.json -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module
|
||||
// RUN: %FileCheck -check-prefix CHECK-SUPPLEMENTAL %s < %t/enums-supplemental.h
|
||||
// RUN: %FileCheck -check-prefix CHECK-SUPPLEMENTAL %s -input-file %t/enums-supplemental.h
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
@@ -26,12 +26,12 @@ import Foundation
|
||||
|
||||
// NEGATIVE-NOT: NSMalformedEnumMissingTypedef :
|
||||
// NEGATIVE-NOT: enum EnumNamed
|
||||
// CHECK-LABEL: enum FooComments : NSInteger;
|
||||
// CHECK-LABEL: enum NegativeValues : int16_t;
|
||||
// CHECK-LABEL: enum ObjcEnumNamed : NSInteger;
|
||||
// CHECK-LABEL: typedef SWIFT_ENUM_FWD_DECL(NSInteger, FooComments)
|
||||
// CHECK-LABEL: typedef SWIFT_ENUM_FWD_DECL(int16_t, NegativeValues)
|
||||
// CHECK-LABEL: typedef SWIFT_ENUM_FWD_DECL(NSInteger, ObjcEnumNamed)
|
||||
|
||||
// CHECK-SUPPLEMENTAL: enum NegativeValues : int16_t;
|
||||
// CHECK-SUPPLEMENTAL: enum ObjcEnumNamed : NSInteger;
|
||||
// CHECK-SUPPLEMENTAL: typedef SWIFT_ENUM_FWD_DECL(int16_t, NegativeValues)
|
||||
// CHECK-SUPPLEMENTAL: typedef SWIFT_ENUM_FWD_DECL(NSInteger, ObjcEnumNamed)
|
||||
|
||||
// CHECK-LABEL: @interface AnEnumMethod
|
||||
// CHECK-NEXT: - (enum NegativeValues)takeAndReturnEnum:(enum FooComments)foo SWIFT_WARN_UNUSED_RESULT;
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
// CHECK-LABEL: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning
|
||||
// CHECK-NEXT: #pragma clang diagnostic
|
||||
// CHECK-NEXT: #endif
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
// CHECK: #pragma clang diagnostic push
|
||||
|
||||
// CHECK-LABEL: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK: #if __has_feature(objc_modules)
|
||||
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
|
||||
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||
// CHECK-NEXT: #endif
|
||||
|
||||
@@ -75,7 +75,7 @@ public struct WrapperStruct {
|
||||
class EnumCase {
|
||||
@objc
|
||||
func foo(@WrapperEnum _ ref: Int) throws {} // expected-error {{method cannot be marked '@objc' because the type of the parameter cannot be represented in Objective-C}}
|
||||
// expected-note@-1 {{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
// expected-note@-1 {{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
|
||||
@@ -31,7 +31,7 @@ enum UnderscoreCDeclEnum: CInt { case A, B }
|
||||
func swiftStruct(x: SwiftStruct) {} // expected-error{{cannot be represented}} expected-note{{Swift struct}}
|
||||
|
||||
@_cdecl("swiftEnum")
|
||||
func swiftEnum(x: SwiftEnum) {} // expected-error{{cannot be represented}} expected-note{{non-'@objc' enum}}
|
||||
func swiftEnum(x: SwiftEnum) {} // expected-error{{cannot be represented}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
@_cdecl("cEnum")
|
||||
func cEnum(x: CEnum) {}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
// RUN: %target-swift-frontend -typecheck %s \
|
||||
// RUN: -enable-experimental-feature CDecl
|
||||
// RUN: %target-swift-frontend -typecheck %s
|
||||
|
||||
// REQUIRES: swift_feature_CDecl
|
||||
|
||||
@c(cdecl_foo) func foo() { } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
@c(cdecl_foo) func foo() { }
|
||||
|
||||
var computed: Int {
|
||||
@c(get_computed) get { return 0 } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
@c(set_computed) set { } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
@c(get_computed) get { return 0 }
|
||||
@c(set_computed) set { }
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ extension String: @retroactive _ObjectiveCBridgeable {
|
||||
|
||||
// Other bad cases
|
||||
@IBAction func action30(_: S) {} // expected-error{{method cannot be marked '@IBAction' because the type of the parameter cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
|
||||
@IBAction func action31(_: E) {} // expected-error{{method cannot be marked '@IBAction' because the type of the parameter cannot be represented in Objective-C}} expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@IBAction func action31(_: E) {} // expected-error{{method cannot be marked '@IBAction' because the type of the parameter cannot be represented in Objective-C}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
init() { }
|
||||
}
|
||||
|
||||
@@ -224,10 +224,10 @@ protocol CP2 : class { }
|
||||
@IBSegueAction func action30c(_: AnyObject, _: S, _: AnyObject) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 2 cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action30d(_: AnyObject, _: AnyObject, _: S) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 3 cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
|
||||
|
||||
@IBSegueAction func action31a(_: AnyObject, _: AnyObject, _: AnyObject) -> E {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because its result type cannot be represented in Objective-C}} expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31b(_: E, _: AnyObject, _: AnyObject) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 1 cannot be represented in Objective-C}} expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31c(_: AnyObject, _: E, _: AnyObject) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 2 cannot be represented in Objective-C}} expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31d(_: AnyObject, _: AnyObject, _: E) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 3 cannot be represented in Objective-C}} expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31a(_: AnyObject, _: AnyObject, _: AnyObject) -> E {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because its result type cannot be represented in Objective-C}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31b(_: E, _: AnyObject, _: AnyObject) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 1 cannot be represented in Objective-C}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31c(_: AnyObject, _: E, _: AnyObject) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 2 cannot be represented in Objective-C}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
@IBSegueAction func action31d(_: AnyObject, _: AnyObject, _: E) -> AnyObject {fatalError()} // expected-error{{method cannot be marked '@IBSegueAction' because the type of the parameter 3 cannot be represented in Objective-C}} expected-note{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
// Supported arities
|
||||
@IBSegueAction func actionWith0() -> X {fatalError()} // expected-error{{@IBSegueAction methods must have 1 to 3 arguments}}
|
||||
|
||||
@@ -639,7 +639,7 @@ class subject_subscriptInvalid4 {
|
||||
class subject_subscriptInvalid5 {
|
||||
@objc // bad-access-note-move{{subject_subscriptInvalid5.subscript(_:)}}
|
||||
subscript(a: PlainEnum) -> Int { // access-note-adjust{{@objc}} expected-error {{subscript cannot be marked '@objc' because its type cannot be represented in Objective-C}}
|
||||
// expected-note@-1{{enums cannot be represented in Objective-C}}
|
||||
// expected-note@-1{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
get { return 0 }
|
||||
}
|
||||
}
|
||||
@@ -765,7 +765,7 @@ class infer_instanceFunc1 {
|
||||
@objc // bad-access-note-move{{infer_instanceFunc1.func11_(a:)}}
|
||||
func func11_(a: PlainEnum) {}
|
||||
// access-note-adjust{{@objc}} expected-error@-1 {{instance method cannot be marked '@objc' because the type of the parameter cannot be represented in Objective-C}}
|
||||
// expected-note@-2 {{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
// expected-note@-2{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
func func12(a: PlainProtocol) {}
|
||||
// CHECK-LABEL: {{^}} func func12(a: any PlainProtocol) {
|
||||
@@ -881,7 +881,7 @@ class infer_instanceFunc1 {
|
||||
// access-note-adjust{{@objc}} expected-error@-1 {{instance method cannot be marked '@objc' because the type of the parameter 1 cannot be represented in Objective-C}}
|
||||
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
|
||||
// access-note-adjust{{@objc}} expected-error@-3 {{instance method cannot be marked '@objc' because the type of the parameter 2 cannot be represented in Objective-C}}
|
||||
// expected-note@-4 {{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
// expected-note@-4{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
// Produces an extra: expected-note@-5 * {{attribute 'objc' was added by access note for fancy tests}}
|
||||
|
||||
@objc // access-note-move{{infer_instanceFunc1.func_UnnamedParam1(_:)}}
|
||||
@@ -1101,7 +1101,7 @@ class infer_instanceVar1 {
|
||||
@objc // bad-access-note-move{{infer_instanceVar1.var_PlainEnum_}}
|
||||
var var_PlainEnum_: PlainEnum
|
||||
// access-note-adjust{{@objc}} expected-error@-1 {{property cannot be marked '@objc' because its type cannot be represented in Objective-C}}
|
||||
// expected-note@-2 {{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
// expected-note@-2{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
var var_PlainProtocol: PlainProtocol
|
||||
// CHECK-LABEL: {{^}} var var_PlainProtocol: any PlainProtocol
|
||||
@@ -2322,7 +2322,7 @@ class ClassThrows1 {
|
||||
@objc // bad-access-note-move{{ClassThrows1.fooWithErrorEnum1(x:)}}
|
||||
func fooWithErrorEnum1(x: ErrorEnum) {}
|
||||
// access-note-adjust{{@objc}} expected-error@-1{{instance method cannot be marked '@objc' because the type of the parameter cannot be represented in Objective-C}}
|
||||
// expected-note@-2{{non-'@objc' enums cannot be represented in Objective-C}}
|
||||
// expected-note@-2{{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
// CHECK: {{^}} func fooWithErrorEnum2(x: ErrorEnum)
|
||||
func fooWithErrorEnum2(x: ErrorEnum) {}
|
||||
|
||||
Reference in New Issue
Block a user