Skip to content

Commit 744b157

Browse files
authored
Test that initializers inherit '@objc' from convenience inits (#23305)
This is weird behavior---there's no 'override' keyword here or anything! But we rely on it when a convenience initializer written in Objective-C dispatches to another convenience initializer. Changing this /will/ break some Apple Objective-C classes that are meant to be subclassed, unfortunately.
1 parent 4e264b4 commit 744b157

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/attr/attr_objc_swift4.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 4 -enable-source-import -I %S/Inputs
2+
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs | %FileCheck %s
23
// REQUIRES: objc_interop
34

45
import Foundation
@@ -30,3 +31,42 @@ class BadInSwift4 {
3031
@GKInspectable var badGKInspectable: PlainStruct?
3132
// expected-error@-1{{property cannot be marked @GKInspectable because its type cannot be represented in Objective-C}}
3233
}
34+
35+
// CHECK-LABEL: class InitsInheritObjCAttrBase
36+
class InitsInheritObjCAttrBase: NSObject {
37+
override init() {}
38+
// CHECK: {{^}} @objc convenience init(foo: Int)
39+
@objc convenience init(foo: Int) { self.init() }
40+
} // CHECK: {{^[}]$}}
41+
42+
// CHECK-LABEL: extension InitsInheritObjCAttrBase
43+
extension InitsInheritObjCAttrBase {
44+
// CHECK: {{^}} @objc convenience dynamic init(bar: Int)
45+
@objc convenience init(bar: Int) { self.init() }
46+
} // CHECK: {{^[}]$}}
47+
48+
// CHECK-LABEL: class ConvenienceInitsInheritObjCAttrSub
49+
class ConvenienceInitsInheritObjCAttrSub: InitsInheritObjCAttrBase {
50+
init(somethingElse: ()) { super.init() }
51+
52+
// CHECK: {{^}} @objc convenience init(foo: Int)
53+
convenience init(foo: Int) { self.init(somethingElse: ()) }
54+
// FIXME: The '@objc' is relied upon, but the 'dynamic' probably shouldn't be!
55+
// CHECK: {{^}} @objc convenience dynamic init(bar: Int)
56+
convenience init(bar: Int) { self.init(somethingElse: ()) }
57+
58+
// CHECK: {{^}} convenience init(unrelated: Int)
59+
convenience init(unrelated: Int) { self.init(somethingElse: ()) }
60+
} // CHECK: {{^[}]$}}
61+
62+
// CHECK-LABEL: class DesignatedInitsInheritObjCAttrSub
63+
class DesignatedInitsInheritObjCAttrSub: InitsInheritObjCAttrBase {
64+
// CHECK: {{^}} @objc init(foo: Int)
65+
init(foo: Int) { super.init() }
66+
// FIXME: The '@objc' is relied upon, but the 'dynamic' probably shouldn't be!
67+
// CHECK: {{^}} @objc dynamic init(bar: Int)
68+
init(bar: Int) { super.init() }
69+
70+
// CHECK: {{^}} init(unrelated: Int)
71+
init(unrelated: Int) { super.init() }
72+
} // CHECK: {{^[}]$}}

0 commit comments

Comments
 (0)