Files
swift-mirror/test/attr/attr_objc_swift3_deprecated.swift
Jordan Rose f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00

44 lines
2.3 KiB
Swift

// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3 -warn-swift3-objc-inference-complete
// REQUIRES: objc_interop
import Foundation
class ObjCSubclass : NSObject {
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
// expected-note@-1{{add `@objc` to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
// expected-note@-2{{add `@nonobjc` to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
var bar: NSObject? = nil // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
// expected-note@-1{{add `@objc` to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
// expected-note@-2{{add `@nonobjc` to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
}
class DynamicMembers {
dynamic func foo() { } // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
dynamic var bar: NSObject? = nil // expected-warning{{inference of '@objc' for 'dynamic' members is deprecated}}{{3-3=@objc }}
}
class GenericClass<T>: NSObject {}
class SubclassOfGeneric: GenericClass<Int> {
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
// expected-note@-1{{add `@objc` to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
// expected-note@-2{{add `@nonobjc` to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
}
@objc(SubclassOfGenericCustom)
class SubclassOfGenericCustomName: GenericClass<Int> {
func foo() { } // expected-warning{{inference of '@objc' for members of Objective-C-derived classes is deprecated}}
// expected-note@-1{{add `@objc` to continue exposing an Objective-C entry point (Swift 3 behavior)}}{{3-3=@objc }}
// expected-note@-2{{add `@nonobjc` to suppress the Objective-C entry point (Swift 4 behavior)}}{{3-3=@nonobjc }}
}
// Suppress diagnostices about references to inferred @objc declarations
// in this mode.
func test(sc: ObjCSubclass, dm: DynamicMembers) {
_ = #selector(sc.foo)
_ = #selector(getter: dm.bar)
_ = #keyPath(DynamicMembers.bar)
}