Skip to content

Commit 6dcbec8

Browse files
committed
Use Parameter-Specific Diagnostic When Diagnosing Parameters
1 parent ded4dd2 commit 6dcbec8

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,11 @@ static void checkDefaultArguments(ParameterList *params) {
10191019
// Placeholder types are banned for all parameter decls. We try to use the
10201020
// freshly-checked default expression's contextual type to suggest a
10211021
// reasonable type to insert.
1022+
param->diagnose(diag::placeholder_type_not_allowed_in_parameter)
1023+
.highlight(param->getSourceRange());
10221024
if (expr && !expr->getType()->hasError()) {
1023-
param->diagnose(diag::placeholder_type_not_allowed_in_parameter)
1024-
.highlight(param->getSourceRange());
10251025
TypeChecker::notePlaceholderReplacementTypes(
10261026
ifacety, expr->getType()->mapTypeOutOfContext());
1027-
} else {
1028-
param->diagnose(diag::placeholder_type_not_allowed);
10291027
}
10301028
}
10311029
}

test/Sema/placeholder_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func opaque() -> some _ { // expected-error {{type placeholder not allowed here}
249249
}
250250

251251
enum EnumWithPlaceholders {
252-
case topLevelPlaceholder(x: _) // expected-error {{type placeholder not allowed here}}
252+
case topLevelPlaceholder(x: _) // expected-error {{type placeholder may not appear in top-level parameter}}
253253
case placeholderWithDefault(x: _ = 5) // expected-error {{type placeholder may not appear in top-level parameter}}
254254
// expected-note@-1 {{replace the placeholder with the correct type 'Int'}}
255255
}

0 commit comments

Comments
 (0)