Files
swift-mirror/test/attr/attr_objcMembers.swift
Slava Pestov bfcf24ee4e AST: Rework @objcMembers inheritance to not depend on validation order
Sema would directly check for the presence of the @objcMembers attribute,
and inherit it from the immediate superclass in validateDecl().

We don't want validateDecl() to have side effects like this and this was
already a problem, because it would not inherit the attribute transitively
in some cases.

Instead, add a ClassDecl::hasObjCMembers() method that walks over all
ancestors and caches the result.

<rdar://problem/46420252>
2018-12-12 15:12:38 -05:00

47 lines
1.4 KiB
Swift

// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s %S/Inputs/attr_objcMembers_other.swift
// REQUIRES: objc_interop
import Foundation
@objcMembers
class SomeClassWithObjCMembers {
func foo() { }
}
extension SomeClassWithObjCMembers {
var bar: NSObject? { get { return nil } set { } }
}
// @objcMembers is inherited
class SubClassOfSomeClassWithObjCMembers : SomeClassWithObjCMembers {
func baz() { }
// Don't complain about things not expressible in Objective-C.
func notForObjC() -> (Int, Int) { return (0, 0) }
}
extension SubClassOfSomeClassWithObjCMembers {
func wibble() { }
}
class SubClassOfOtherClassWithObjCMembers : OtherClassWithObjCMembers {
func quux() { }
}
// @objc should be inferred for everything referenced here.
func selectorTest() {
_ = #selector(SomeClassWithObjCMembers.foo)
_ = #selector(getter: SomeClassWithObjCMembers.bar)
_ = #selector(SubClassOfSomeClassWithObjCMembers.baz)
_ = #selector(SubClassOfSomeClassWithObjCMembers.wibble)
_ = #selector(SubClassOfOtherClassWithObjCMembers.quux)
}
@nonobjc extension SomeClassWithObjCMembers {
func notInferredObjC() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}
}
func selectorTestFail() {
_ = #selector(SomeClassWithObjCMembers.notInferredObjC) // expected-error{{argument of '#selector' refers to instance method 'notInferredObjC()' that is not exposed to Objective-C}}
}