Skip to content

Commit b47a830

Browse files
author
Harlan Haskins
committed
SE-0066: Added error and fixit for non-parenthesized function param types
1 parent d858cc9 commit b47a830

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ ERROR(expected_type_before_arrow,none,
615615
"expected type before '->'", ())
616616
ERROR(expected_type_after_arrow,none,
617617
"expected type after '->'", ())
618+
ERROR(non_tuple_function_param_type,none,
619+
"type before '->' must be wrapped in parentheses", ())
618620

619621
// Enum Types
620622
ERROR(expected_expr_enum_case_raw_value,PointsToFirstBadToken,

lib/Parse/ParseType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
187187
// Handle type-function if we have an arrow.
188188
SourceLoc arrowLoc;
189189
if (consumeIf(tok::arrow, arrowLoc)) {
190+
if (!isa<TupleTypeRepr>(ty.get())) {
191+
diagnose(ty.get()->getStartLoc(), diag::non_tuple_function_param_type)
192+
.highlight(ty.get()->getSourceRange())
193+
.fixItInsert(ty.get()->getStartLoc(), "(")
194+
.fixItInsertAfter(ty.get()->getEndLoc(), ")");
195+
}
190196
ParserResult<TypeRepr> SecondHalf =
191197
parseType(diag::expected_type_function_result);
192198
if (SecondHalf.hasCodeCompletion())

0 commit comments

Comments
 (0)