Skip to content

Commit 3bbffde

Browse files
committed
[Parse] Remove a/an from 'missing condition' diagnostics
1 parent bfc68f4 commit 3bbffde

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ ERROR(conditional_var_valid_identifiers_only,none,
10931093
ERROR(expected_condition_if,PointsToFirstBadToken,
10941094
"expected expression, var, or let in 'if' condition", ())
10951095
ERROR(missing_condition_after_if,none,
1096-
"missing condition in an 'if' statement", ())
1096+
"missing condition in 'if' statement", ())
10971097
ERROR(expected_lbrace_after_if,PointsToFirstBadToken,
10981098
"expected '{' after 'if' condition", ())
10991099
ERROR(expected_lbrace_or_if_after_else,PointsToFirstBadToken,
@@ -1109,7 +1109,7 @@ NOTE(suggest_removing_else,none,
11091109
ERROR(expected_condition_guard,PointsToFirstBadToken,
11101110
"expected expression, var, let or case in 'guard' condition", ())
11111111
ERROR(missing_condition_after_guard,none,
1112-
"missing condition in an 'guard' statement", ())
1112+
"missing condition in 'guard' statement", ())
11131113
ERROR(expected_else_after_guard,PointsToFirstBadToken,
11141114
"expected 'else' after 'guard' condition", ())
11151115
ERROR(expected_lbrace_after_guard,PointsToFirstBadToken,
@@ -1119,7 +1119,7 @@ ERROR(expected_lbrace_after_guard,PointsToFirstBadToken,
11191119
ERROR(expected_condition_while,PointsToFirstBadToken,
11201120
"expected expression, var, or let in 'while' condition", ())
11211121
ERROR(missing_condition_after_while,none,
1122-
"missing condition in a 'while' statement", ())
1122+
"missing condition in 'while' statement", ())
11231123
ERROR(expected_lbrace_after_while,PointsToFirstBadToken,
11241124
"expected '{' after 'while' condition", ())
11251125

test/Parse/guard.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func noConditionNoElse() {
4+
guard {} // expected-error {{missing condition in 'guard' statement}} expected-error {{expected 'else' after 'guard' condition}}
5+
}
6+
func noCondition() {
7+
guard else {} // expected-error {{missing condition in 'guard' statement}}
8+
}

test/Parse/recovery.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,60 +79,60 @@ class ClassWithStaticDecls {
7979
func missingControllingExprInIf() {
8080
if // expected-error {{expected expression, var, or let in 'if' condition}}
8181

82-
if { // expected-error {{missing condition in an 'if' statement}}
82+
if { // expected-error {{missing condition in 'if' statement}}
8383
}
8484

85-
if // expected-error {{missing condition in an 'if' statement}}
85+
if // expected-error {{missing condition in 'if' statement}}
8686
{
8787
}
8888

8989
if true {
90-
} else if { // expected-error {{missing condition in an 'if' statement}}
90+
} else if { // expected-error {{missing condition in 'if' statement}}
9191
}
9292

9393
// It is debatable if we should do recovery here and parse { true } as the
9494
// body, but the error message should be sensible.
95-
if { true } { // expected-error {{missing condition in an 'if' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{14-14=;}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{15-15=do }} expected-warning {{boolean literal is unused}}
95+
if { true } { // expected-error {{missing condition in 'if' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{14-14=;}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{15-15=do }} expected-warning {{boolean literal is unused}}
9696
}
9797

98-
if { true }() { // expected-error {{missing condition in an 'if' statement}} expected-error 2 {{consecutive statements on a line must be separated by ';'}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{17-17=do }} expected-warning {{boolean literal is unused}}
98+
if { true }() { // expected-error {{missing condition in 'if' statement}} expected-error 2 {{consecutive statements on a line must be separated by ';'}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{17-17=do }} expected-warning {{boolean literal is unused}}
9999
}
100100

101101
// <rdar://problem/18940198>
102-
if { { } } // expected-error{{missing condition in an 'if' statement}} expected-error{{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{8-8=do }}
102+
if { { } } // expected-error{{missing condition in 'if' statement}} expected-error{{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{8-8=do }}
103103
}
104104

105105
func missingControllingExprInWhile() {
106106
while // expected-error {{expected expression, var, or let in 'while' condition}}
107107

108-
while { // expected-error {{missing condition in a 'while' statement}}
108+
while { // expected-error {{missing condition in 'while' statement}}
109109
}
110110

111-
while // expected-error {{missing condition in a 'while' statement}}
111+
while // expected-error {{missing condition in 'while' statement}}
112112
{
113113
}
114114

115115
// It is debatable if we should do recovery here and parse { true } as the
116116
// body, but the error message should be sensible.
117-
while { true } { // expected-error {{missing condition in a 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{17-17=;}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{18-18=do }} expected-warning {{boolean literal is unused}}
117+
while { true } { // expected-error {{missing condition in 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{17-17=;}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{18-18=do }} expected-warning {{boolean literal is unused}}
118118
}
119119

120-
while { true }() { // expected-error {{missing condition in a 'while' statement}} expected-error 2 {{consecutive statements on a line must be separated by ';'}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{20-20=do }} expected-warning {{boolean literal is unused}}
120+
while { true }() { // expected-error {{missing condition in 'while' statement}} expected-error 2 {{consecutive statements on a line must be separated by ';'}} expected-error {{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{20-20=do }} expected-warning {{boolean literal is unused}}
121121
}
122122

123123
// <rdar://problem/18940198>
124-
while { { } } // expected-error{{missing condition in a 'while' statement}} expected-error{{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{11-11=do }}
124+
while { { } } // expected-error{{missing condition in 'while' statement}} expected-error{{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{11-11=do }}
125125
}
126126

127127
func missingControllingExprInRepeatWhile() {
128128
repeat {
129-
} while // expected-error {{missing condition in a 'while' statement}}
129+
} while // expected-error {{missing condition in 'while' statement}}
130130
{ // expected-error{{closure expression is unused}} expected-note {{did you mean to use a 'do' statement?}} {{3-3=do }}
131131
missingControllingExprInRepeatWhile();
132132
}
133133

134134
repeat {
135-
} while { true }() // expected-error{{missing condition in a 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{10-10=;}} expected-warning {{result of call to closure returning 'Bool' is unused}}
135+
} while { true }() // expected-error{{missing condition in 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{10-10=;}} expected-warning {{result of call to closure returning 'Bool' is unused}}
136136
}
137137

138138
// SR-165

0 commit comments

Comments
 (0)