forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverload_noncall.swift
70 lines (55 loc) · 1.83 KB
/
overload_noncall.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
// RUN: %target-parse-verify-swift
struct X { }
struct Y { }
struct Z { }
func f0(x1: X, x2: X) -> X {} // expected-note{{found this candidate}}
func f0(y1: Y, y2: Y) -> Y {} // expected-note{{found this candidate}}
var f0 : X // expected-note {{found this candidate}} expected-note {{'f0' previously declared here}}
func f0_init(x: X, y: Y) -> X {}
var f0 : (x : X, y : Y) -> X = f0_init // expected-error{{invalid redeclaration}}
func f1(x: X) -> X {}
func f2(g: (x: X) -> X) -> ((y: Y) -> Y) { }
func test_conv() {
var _ : (x1 : X, x2 : X) -> X = f0
var _ : (X, X) -> X = f0
var _ : (Y, X) -> X = f0 // expected-error{{ambiguous reference to member 'f0'}}
var _ : (X) -> X = f1
var a7 : (X) -> (X) = f1
var a8 : (x2 : X) -> (X) = f1
var a9 : (x2 : X) -> ((X)) = f1
a7 = a8
a8 = a9
a9 = a7
var _ : ((X) -> X) -> ((Y) -> Y) = f2
var _ : ((x2 : X) -> (X)) -> (((y2 : Y) -> (Y))) = f2
typealias fp = ((X) -> X) -> ((Y) -> Y)
var _ = f2
}
var xy : X // expected-note {{previously declared here}}
var xy : Y // expected-error {{invalid redeclaration of 'xy'}}
func accept_X(inout x: X) { }
func accept_XY(inout x: X) -> X { }
func accept_XY(inout y: Y) -> Y { }
func accept_Z(inout z: Z) -> Z { }
func test_inout() {
var x : X
accept_X(&x);
accept_X(xy); // expected-error{{passing value of type 'X' to an inout parameter requires explicit '&'}} {{12-12=&}}
accept_X(&xy);
accept_XY(&x);
x = accept_XY(&xy);
x = xy
x = &xy; // expected-error{{'&' used with non-inout argument of type 'X'}}
accept_Z(&xy); // expected-error{{cannot convert value of type 'X' to expected argument type 'Z'}}
}
func lvalue_or_rvalue(inout x: X) -> X { }
func lvalue_or_rvalue(x: X) -> Y { }
func test_lvalue_or_rvalue() {
var x : X
var y : Y
let x1 = lvalue_or_rvalue(&x)
x = x1
let y1 = lvalue_or_rvalue(x)
y = y1
_ = y
}