forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment.swift
51 lines (41 loc) · 1020 Bytes
/
assignment.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
// RUN: %target-parse-verify-swift
struct X { }
struct Y { }
struct WithOverloadedSubscript {
subscript(i: Int) -> X {
get {}
set {}
}
subscript(i: Int) -> Y {
get {}
set {}
}
}
func test_assign() {
var a = WithOverloadedSubscript()
a[0] = X()
a[0] = Y()
}
var i: X
var j: X
var f: Y
func getXY() -> (X, Y) {}
var ift : (X, Y)
var ovl = WithOverloadedSubscript()
var slice: [X]
i = j
(i, f) = getXY()
(i, f) = ift
(i, f) = (i, f)
(ovl[0], ovl[0]) = ift
(ovl[0], ovl[0]) = (i, f)
(_, ovl[0]) = (i, f)
(ovl[0], _) = (i, f)
_ = (i, f)
slice[7] = i
slice[7] = f // expected-error{{cannot assign value of type 'Y' to type 'X'}}
slice[7] = _ // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
func value(x: Int) {}
func value2(inout x: Int) {}
value2(&_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
value(_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}