mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Though the value may be statically known in some cases, that isn't good enough to do what we try to do with this information. In particular, if we invoke a class method on a MetatypeConversion, we want to dispatch to the method of the original metatype, not statically call the method of the converted type, which is what is evident in the AST. Fixes rdar://problem/18877135. Swift SVN r23277
114 lines
2.8 KiB
Swift
114 lines
2.8 KiB
Swift
// RUN: %target-run-simple-swift | FileCheck %s
|
|
|
|
// Test initialization and initializer inheritance.
|
|
var depth = 0
|
|
|
|
func printAtDepth(s: String) {
|
|
for i in 0..<depth { print("*") }
|
|
println(s)
|
|
}
|
|
|
|
class A {
|
|
var int: Int
|
|
var string: String
|
|
|
|
convenience init() {
|
|
printAtDepth("Starting A.init()")
|
|
++depth
|
|
self.init(int:5)
|
|
--depth
|
|
printAtDepth("Ending A.init()")
|
|
}
|
|
|
|
convenience init(int i:Int) {
|
|
printAtDepth("Starting A.init withInt(\(i))")
|
|
++depth
|
|
self.init(int:i, string:"hello")
|
|
--depth
|
|
printAtDepth("Ending A.init withInt(\(i))")
|
|
}
|
|
|
|
init(int i:Int, string: String) {
|
|
printAtDepth("Starting A.init withInt(\(i)) string(\(string))")
|
|
self.int = i
|
|
self.string = string
|
|
printAtDepth("Ending A.init withInt(\(i)) string(\(string))")
|
|
}
|
|
|
|
deinit {
|
|
printAtDepth("A.deinit")
|
|
}
|
|
}
|
|
|
|
class B : A {
|
|
var double: Double
|
|
|
|
convenience override init(int i:Int, string: String) {
|
|
printAtDepth("Starting B.init withInt(\(i)) string(\(string))")
|
|
++depth
|
|
self.init(int: i, string:string, double:3.14159)
|
|
--depth
|
|
printAtDepth("Ending B.init withInt(\(i)) string(\(string))")
|
|
}
|
|
|
|
init(int i:Int, string: String, double:Double) {
|
|
printAtDepth("Starting B.init withInt(\(i)) string(\(string)) double(\(double))")
|
|
self.double = double
|
|
++depth
|
|
super.init(int: i, string: string)
|
|
--depth
|
|
printAtDepth("Ending B.init withInt(\(i)) string(\(string)) double(\(double))")
|
|
}
|
|
|
|
deinit {
|
|
printAtDepth("B.deinit")
|
|
}
|
|
}
|
|
|
|
class C : B {
|
|
override init(int i:Int, string: String, double: Double) {
|
|
printAtDepth("Starting C.init withInt(\(i)) string(\(string)) double(\(double))")
|
|
++depth
|
|
super.init(int: i, string: string, double: double)
|
|
--depth
|
|
printAtDepth("Ending C.init withInt(\(i)) string(\(string)) double(\(double))")
|
|
}
|
|
|
|
deinit {
|
|
printAtDepth("C.deinit")
|
|
}
|
|
}
|
|
|
|
println("-----Constructing C()-----")
|
|
// CHECK: Starting A.init()
|
|
// CHECK: *Starting A.init withInt(5)
|
|
// CHECK: **Starting B.init withInt(5) string(hello)
|
|
// CHECK: ***Starting C.init withInt(5) string(hello) double(3.14159)
|
|
// CHECK: ****Starting B.init withInt(5) string(hello) double(3.14159)
|
|
// CHECK: *****Starting A.init withInt(5) string(hello)
|
|
// CHECK: *****Ending A.init withInt(5) string(hello)
|
|
// CHECK: ****Ending B.init withInt(5) string(hello) double(3.14159)
|
|
// CHECK: ***Ending C.init withInt(5) string(hello) double(3.14159)
|
|
// CHECK: **Ending B.init withInt(5) string(hello)
|
|
// CHECK: *Ending A.init withInt(5)
|
|
// CHECK: Ending A.init()
|
|
// CHECK: C.deinit
|
|
// CHECK: B.deinit
|
|
// CHECK: A.deinit
|
|
C()
|
|
|
|
// rdar://problem/18877135
|
|
|
|
class Foo: FloatLiteralConvertible {
|
|
required init(floatLiteral: Float) { }
|
|
|
|
func identify() { println("Foo") }
|
|
}
|
|
|
|
class Bar: Foo {
|
|
override func identify() { println("Bar") }
|
|
}
|
|
|
|
let x: Bar = 1.0
|
|
x.identify() // CHECK-LABEL: Bar
|