forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjc_override.swift
90 lines (65 loc) · 3.02 KB
/
objc_override.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -I %S/Inputs/custom-modules %s -verify
// REQUIRES: objc_interop
import Foundation
import ObjCParseExtras
class MyArray : DummyClass {
func setBoolProperty(x: Bool) { } // expected-error{{method 'setBoolProperty' with Objective-C selector 'setBoolProperty:' conflicts with setter for 'boolProperty' from superclass 'DummyClass' with the same Objective-C selector}}
@objc(objectAtIndexedSubscript:)
func getObjectAt(i: Int) { } // expected-error{{method 'getObjectAt' with Objective-C selector 'objectAtIndexedSubscript:' conflicts with method 'objectAtIndexedSubscript' from superclass 'DummyClass' with the same Objective-C selector}}
}
class SomeCellSub1 : SomeCell {
init(string: String) { super.init(string: string) } // expected-error{{overriding declaration requires an 'override' keyword}}{{3-3=override }}
// okay: should not conflict
func initWithString(string: String) { }
var enabled: Bool { // expected-error{{overriding declaration requires an 'override' keyword}}
get { return super.enabled }
}
@objc(enabled)
func otherIsEnabled() { } // should not conflict
}
class SomeCellSub2 : SomeCell {
override init(string: String) { super.init(string: string) }
// okay: should not conflict
func initWithString(string: String) { }
override var enabled: Bool {
get { return super.enabled }
}
@objc(enabled)
func otherIsEnabled() { } // should not conflict
}
class SomeCellSub3 : SomeCell {
@objc(initString:)
override init(string: String) { super.init(string: string) }
// okay: should not conflict
func initWithString(string: String) { }
override var enabled: Bool {
@objc(isEnabled) get { return super.enabled }
}
@objc(enabled)
func otherIsEnabled() { } // should not conflict
}
class SomeCellSub4 : SomeCell {
@objc
override init(string: String) { super.init(string: string) }
// okay: should not conflict
func initWithString(string: String) { }
override var enabled: Bool {
@objc get { return super.enabled }
}
@objc(enabled)
func otherIsEnabled() { } // should not conflict
}
class SomeCellSub5 : SomeCell {
@objc(initWithString:) // expected-error{{Objective-C method has a different selector from the method it overrides ('initWithString:' vs. 'initString:')}}{{9-24=initString:}}
override init(string: String) { super.init(string: string) }
override var enabled: Bool {
@objc(wasEnabled) get { return super.enabled }
// expected-error@-1{{Objective-C method has a different selector from the method it overrides ('wasEnabled' vs. 'isEnabled')}}{{11-21=isEnabled}}
}
@objc(enabled)
func otherIsEnabled() { } // should not conflict
}
class FailSub : FailBase {
override init(value: Int) { try! super.init(value: value) } // expected-error {{overriding a throwing @objc initializer with a non-throwing initializer is not supported}}
override class func processValue() {} // expected-error {{overriding a throwing @objc method with a non-throwing method is not supported}}
}