forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeof.swift
83 lines (65 loc) · 1.53 KB
/
typeof.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
// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test
protocol Fooable { static func foo() }
class B : Fooable {
class func foo() { print("Beads?!") }
}
class D : B {
override class func foo() { print("Deeds?!") }
}
struct S : Fooable {
static func foo() { print("Seeds?!") }
}
func classMetatype(b: B.Type) {
b.foo()
}
func structMetatype(s: S.Type) {
s.foo()
}
func archeMetatype<T : Fooable>(t: T.Type) {
t.foo()
}
func archeMetatype2<T : Fooable>(t: T) {
t.dynamicType.foo()
}
func boxedExistentialMetatype(e: ErrorType) -> ErrorType.Type {
return e.dynamicType
}
enum Hangry : ErrorType {
case Hungry, Angry
}
class Meltdown : ErrorType {
var _domain : String {
return "_domain"
}
var _code : Int {
return 420
}
}
class GrilledCheese : Meltdown {}
// CHECK: Beads?
classMetatype(B().dynamicType)
// CHECK: Deeds?
classMetatype(D().dynamicType)
// CHECK: Seeds?
structMetatype(S().dynamicType)
// CHECK: Beads?
archeMetatype(B().dynamicType)
// FIXME: Deeds? <rdar://problem/14620454>
archeMetatype(D().dynamicType)
// CHECK: Seeds?
archeMetatype(S().dynamicType)
// CHECK: Beads?
archeMetatype2(B())
// FIXME: Deeds? <rdar://problem/14620454>
archeMetatype2(D())
// CHECK: Seeds?
archeMetatype2(S())
// CHECK: Hangry
print(boxedExistentialMetatype(Hangry.Hungry))
// CHECK: Meltdown
print(boxedExistentialMetatype(Meltdown()))
// CHECK: GrilledCheese
print(boxedExistentialMetatype(GrilledCheese()))
// CHECK: GrilledCheese
print(boxedExistentialMetatype(GrilledCheese() as Meltdown))