-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathdo_expr_disabled.swift
130 lines (108 loc) · 4.08 KB
/
do_expr_disabled.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// RUN: %target-typecheck-verify-swift
// Currently disabled by default.
func throwsError() throws -> Int { 0 }
func test1() -> Int {
return do { 5 }
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{non-void function should return a value}}
// expected-warning@-3 {{integer literal is unused}}
}
func test2() -> Int {
return do { try throwsError() } catch { 0 }
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{non-void function should return a value}}
// expected-warning@-3 {{integer literal is unused}}
// expected-warning@-4 {{result of call to 'throwsError()' is unused}}
}
func test3() -> Int {
return
do { 5 }
// expected-error@-2 {{non-void function should return a value}}
// expected-warning@-2 {{integer literal is unused}}
}
func test4() -> Int {
return
do { try throwsError() } catch { 0 }
// expected-error@-2 {{non-void function should return a value}}
// expected-warning@-2 {{integer literal is unused}}
// expected-warning@-3 {{result of call to 'throwsError()' is unused}}
}
func test5() -> Int {
do { 5 } // expected-warning {{integer literal is unused}}
}
func test6() -> Int {
do { try throwsError() } catch { 0 }
// expected-warning@-1 {{integer literal is unused}}
// expected-warning@-2 {{result of call to 'throwsError()' is unused}}
}
func test7() -> Int {
do { 5 } as Int
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-warning@-2 {{integer literal is unused}}
// expected-error@-3 {{expected expression}}
}
func test8() -> Int {
do { try throwsError() } catch { 0 } as Int
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-warning@-2 {{integer literal is unused}}
// expected-error@-3 {{expected expression}}
// expected-warning@-4 {{result of call to 'throwsError()' is unused}}
}
func test9() -> Int {
let x = do { 5 }
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{expected initial value after '='}}
// expected-warning@-3 {{integer literal is unused}}
return x
}
func test10() -> Int {
let x = do { try throwsError() } catch { 0 }
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{expected initial value after '='}}
// expected-warning@-3 {{integer literal is unused}}
// expected-warning@-4 {{result of call to 'throwsError()' is unused}}
return x
}
func test11() -> Int {
let fn = { do { 5 } }
// expected-warning@-1 {{integer literal is unused}}
return fn() // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
}
func test12() -> Int {
let fn = { do { try throwsError() } catch { 0 } }
// expected-warning@-1 {{integer literal is unused}}
// expected-warning@-2 {{result of call to 'throwsError()' is unused}}
return fn() // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
}
func test13() -> Int {
let x = if .random() {
do { 0 } // expected-warning {{integer literal is unused}}
} else { // expected-error {{non-expression branch of 'if' expression may only end with a 'throw'}}
1
}
return x
}
func test14() -> Int {
let x = if .random() {
1
} else {
do { 2 } catch { 3 } // expected-warning 2{{integer literal is unused}}
// expected-warning@-1 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
} // expected-error {{non-expression branch of 'if' expression may only end with a 'throw'}}
return x
}
func test15() -> Int {
if .random() {
do { 0 } // expected-warning {{integer literal is unused}}
} else {
1 // expected-warning {{integer literal is unused}}
}
}
func test16() -> Int {
if .random() {
1 // expected-warning {{integer literal is unused}}
} else {
do { 2 } catch { 3 } // expected-warning 2{{integer literal is unused}}
// expected-warning@-1 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
}
}