Skip to content

Commit 628dcd6

Browse files
committed
[Parse] Improve diagnostic for no platform condition argument
Drop the "only one" in the message in this case, as that should only apply for too many args.
1 parent e3257fd commit 628dcd6

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,9 @@ ERROR(unsupported_platform_condition_expression,none,
17511751
"unexpected platform condition "
17521752
"(expected 'os', 'arch', or 'swift')",
17531753
())
1754+
ERROR(platform_condition_expected_argument,none,
1755+
"expected argument to platform condition",
1756+
())
17541757
ERROR(platform_condition_expected_one_argument,none,
17551758
"expected only one argument to platform condition",
17561759
())

lib/Parse/ParseIfConfig.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,11 @@ class ValidateIfConfigCondition :
263263

264264
Expr *Arg = getSingleSubExp(E->getArgs(), *KindName, &D);
265265
if (!Arg) {
266-
D.diagnose(E->getLoc(), diag::platform_condition_expected_one_argument);
266+
if (E->getArgs()->empty()) {
267+
D.diagnose(E->getLoc(), diag::platform_condition_expected_argument);
268+
} else {
269+
D.diagnose(E->getLoc(), diag::platform_condition_expected_one_argument);
270+
}
267271
return nullptr;
268272
}
269273
// '_compiler_version' '(' string-literal ')'

test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func fn_j() {}
9898
#endif
9999
fn_j() // OK
100100

101-
#if foo || bar || nonExistent() // expected-error {{expected only one argument to platform condition}}
101+
#if foo || bar || nonExistent() // expected-error {{expected argument to platform condition}}
102102
#endif
103103

104104
#if FOO = false
@@ -171,5 +171,5 @@ if true {}
171171

172172
// rdar://83017601 Make sure we don't crash
173173
#if canImport()
174-
// expected-error@-1 {{expected only one argument to platform condition}}
174+
// expected-error@-1 {{expected argument to platform condition}}
175175
#endif

0 commit comments

Comments
 (0)