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
|
// RUN: %target-typecheck-verify-swift -parse-as-library
struct S {
init() {
super.init() // expected-error{{'super' cannot be used outside of class members}}
}
}
class D : B {
func foo() {
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
}
init(a:Int) {
super.init()
}
init(f:Int) {
super.init(a: "x")
}
init(g:Int) {
super.init("aoeu") // expected-error{{no exact matches in call to initializer}}
}
init(h:Int) {
var _ : B = super.init() // expected-error{{cannot convert value of type '()' to specified type 'B'}}
}
init(d:Double) {
super.init()
}
}
class B {
var foo : Int
func bar() {}
init() {
}
init(x:Int) { // expected-note{{candidate expects value of type 'Int' for parameter #1}}
}
init(a:UnicodeScalar) { // expected-note {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}}
}
init(b:UnicodeScalar) { // expected-note {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}}
}
init(z:Float) { // expected-note{{candidate expects value of type 'Float' for parameter #1}}
super.init() // expected-error{{'super' members cannot be referenced in a root class}}
}
}
/// https://github.com/apple/swift/issues/45089
/// Bad diagnostic for incorrectly calling private `init`
class C_45089 {
private init() {} // expected-note {{'init()' declared here}}
private init(a: Int) {}
}
class Impl_45089 : C_45089 {
init() {
super.init() // expected-error {{'C_45089' initializer is inaccessible due to 'private' protection level}}
}
}
class A_Priv<T> {
private init(_ foo: T) {}
}
class B_Override<U> : A_Priv<[U]> {
init(_ foo: [U]) { fatalError() } // Ok, because effectively overrides init from parent which is invisible
}
|