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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// RUN: %target-typecheck-verify-swift -enable-objc-interop
@objc class C1 { }
@objc class C2 { }
// ------------------------------------------------------------------------
// Parameters of IUO type.
// ------------------------------------------------------------------------
@objc protocol ParameterIUO1 {
@objc optional func f0(_ x: C1!)
}
@objc class ParameterIUO1a : ParameterIUO1 {
func f0(_ x: C1!) { } // okay: exact match
}
@objc class ParameterIUO1b : ParameterIUO1 {
func f0(_ x: C1) { } // okay: all is permitted with IUO requirements
}
@objc class ParameterIUO1c : ParameterIUO1 {
func f0(_ x: C1?) { } // okay: all is permitted with IUO requirements
}
// ------------------------------------------------------------------------
// Parameters of optional type.
// ------------------------------------------------------------------------
@objc protocol ParameterOpt1 {
@objc optional func f0(_ x: C1?) // expected-note 2{{declared here}}
}
@objc class ParameterOpt1a : ParameterOpt1 {
func f0(_ x: C1?) { } // okay: exact match
}
@objc class ParameterOpt1b : ParameterOpt1 {
func f0(_ x: C1!) { } // expected-warning{{different optionality than expected}}{{18-19=?}}
}
@objc class ParameterOpt1c : ParameterOpt1 {
func f0(_ x: C1) { } // expected-error{{different optionality than required}}{{18-18=?}}
}
// ------------------------------------------------------------------------
// Parameters of non-optional type.
// ------------------------------------------------------------------------
@objc protocol ParameterNonOpt1 {
@objc optional func f0(_ x: C1) // expected-note 3 {{declared here}}
}
@objc class ParameterNonOpt1a : ParameterNonOpt1 {
func f0(_ x: C1) { } // okay: exact match
}
@objc class ParameterNonOpt1b : ParameterNonOpt1 {
func f0(_ x: C1!) { } // expected-warning{{parameter of 'f0' has different optionality than expected by protocol 'ParameterNonOpt1'}}{{18-19=}}
}
@objc class ParameterNonOpt1c : ParameterNonOpt1 {
func f0(_ x: C1?) { } // expected-warning{{parameter of 'f0' has different optionality than expected by protocol 'ParameterNonOpt1'}}{{18-19=}}
}
@objc class ParameterNonOpt1d {
func f0(_ x: C1?) { } // expected-note {{'f0' declared here}} {{none}}
}
extension ParameterNonOpt1d : ParameterNonOpt1 {} // expected-warning{{parameter of 'f0' has different optionality than expected by protocol 'ParameterNonOpt1'}} {{none}}
// ------------------------------------------------------------------------
// Result of IUO type.
// ------------------------------------------------------------------------
@objc protocol ResultIUO1 {
@objc optional func f0() -> C1!
}
@objc class ResultIUO1a : ResultIUO1 {
func f0() -> C1! { return nil } // okay: exact match
}
@objc class ResultIUO1b : ResultIUO1 {
func f0() -> C1 { } // okay: all is permitted with IUO requirements
}
@objc class ResultIUO1c : ResultIUO1 {
func f0() -> C1? { } // okay: all is permitted with IUO requirements
}
// ------------------------------------------------------------------------
// Result of optional type.
// ------------------------------------------------------------------------
@objc protocol ResultOpt1 {
@objc optional func f0() -> C1? // expected-note 2{{declared here}}
}
@objc class ResultOpt1a : ResultOpt1 {
func f0() -> C1? { return nil } // okay: exact match
}
@objc class ResultOpt1b : ResultOpt1 {
func f0() -> C1 { } // expected-warning{{different optionality}}{{18-18=?}}
}
@objc class ResultOpt1c : ResultOpt1 {
func f0() -> C1! { } // expected-warning{{different optionality}}{{18-19=?}}
}
// ------------------------------------------------------------------------
// Result of non-optional type.
// ------------------------------------------------------------------------
@objc protocol ResultNonOpt1 {
@objc optional func f0() -> C1 // expected-note 2 {{declared here}}
}
@objc class ResultNonOpt1a : ResultNonOpt1 {
func f0() -> C1 { } // okay: exact match
}
@objc class ResultNonOpt1b : ResultNonOpt1 {
func f0() -> C1? { } // expected-error{{different optionality than required}}{{18-19=}}
}
@objc class ResultNonOpt1c : ResultNonOpt1 {
func f0() -> C1! { } // expected-warning{{different optionality}}{{18-19=}}
}
// ------------------------------------------------------------------------
// Multiple parameter mismatches
// ------------------------------------------------------------------------
@objc protocol MultiParamsOpt1 {
@objc optional func f0(_ x: C1?, y: C1) // expected-note{{here}}
}
@objc class MultiParamsOpt1a : MultiParamsOpt1 {
func f0(_ x: C1!, y: C1!) { } // expected-warning{{parameters of 'f0(_:y:)' have different optionality than expected}}{{18-19=?}}{{26-27=}}
}
// ------------------------------------------------------------------------
// Parameter and result type mismatches
// ------------------------------------------------------------------------
@objc protocol ParamAndResult1 {
@objc optional func f0(_ x: C1?) -> C1 // expected-note{{here}}
}
@objc class ParamAndResult1a : ParamAndResult1 {
func f0(_ x: C1!) -> C1! { } // expected-warning{{result and parameters of 'f0' have different optionality than expected}}{{18-19=?}}{{26-27=}}
}
|