forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteback.swift
92 lines (72 loc) · 1.29 KB
/
writeback.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
90
91
// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test
struct Foo {
var _x : (Int, UnicodeScalar, String)
var x : (Int, String, UnicodeScalar) {
get {
var (a, b, c) = _x
return (a, c, b)
}
mutating
set {
var (a, b, c) = newValue
_x = (a, c, b)
}
}
init(a:Int, b:String, c:UnicodeScalar) {
_x = (a, c, b)
}
}
var foo = Foo(a: 1, b: "two", c: "3")
foo.x.0 = 4
foo.x.1 = "five"
foo.x.2 = "6"
// CHECK: 4
// CHECK: five
// CHECK: 6
print(foo.x.0)
print(foo.x.1)
print(foo.x.2)
struct Bar {
var _foo : Foo
var foo : Foo {
get {
return _foo
}
mutating
set {
_foo = newValue
}
}
}
var bar = Bar(_foo: Foo(a: 1, b: "two", c: "3"))
bar.foo.x.0 = 7
bar.foo.x.1 = "eight"
bar.foo.x.2 = "9"
// CHECK: 7
// CHECK: eight
// CHECK: 9
print(bar.foo.x.0)
print(bar.foo.x.1)
print(bar.foo.x.2)
(foo, bar.foo) = (bar.foo, foo)
// CHECK: 4
// CHECK: five
// CHECK: 6
print(bar.foo.x.0)
print(bar.foo.x.1)
print(bar.foo.x.2)
(foo.x, bar.foo.x) = (bar.foo.x, foo.x)
// CHECK: 7
// CHECK: eight
// CHECK: 9
print(bar.foo.x.0)
print(bar.foo.x.1)
print(bar.foo.x.2)
(foo.x.0, bar.foo.x.0) = (bar.foo.x.0, foo.x.0)
// CHECK: 4
// CHECK: eight
// CHECK: 9
print(bar.foo.x.0)
print(bar.foo.x.1)
print(bar.foo.x.2)