Skip to content

Commit 06424ee

Browse files
committed
[Diagnostics] Resolve SR-11677: Offer a better diagnostic when && is used in trailing where clause declaration
1 parent 5f5134c commit 06424ee

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,8 @@ ERROR(expected_generics_type_restriction,none,
15241524
(Identifier))
15251525
ERROR(requires_single_equal,none,
15261526
"use '==' for same-type requirements rather than '='", ())
1527+
ERROR(requires_comma,none,
1528+
"expected ',' to separate the requirements of this 'where' clause", ())
15271529
ERROR(expected_requirement_delim,none,
15281530
"expected ':' or '==' to indicate a conformance or same-type requirement",
15291531
())

lib/Parse/ParseGeneric.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ ParserStatus Parser::parseGenericWhereClause(
368368
BodyContext.reset();
369369
HasNextReq = consumeIf(tok::comma);
370370
// If there's a comma, keep parsing the list.
371+
// If there's a "&&", diagnose replace with a comma and keep parsing
372+
if (Tok.isBinaryOperator() && Tok.getText() == "&&" && !HasNextReq) {
373+
diagnose(Tok, diag::requires_comma)
374+
.fixItReplace(SourceRange(Tok.getLoc()), ",");
375+
consumeToken();
376+
HasNextReq = true;
377+
}
371378
} while (HasNextReq);
372379

373380
if (Requirements.empty())

test/Parse/rdar38225184.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
extension Collection where Element == Int && Index == Int {}
4+
// expected-error@-1 {{expected ',' to separate the requirements of this 'where' clause}} {{43-45=,}}

0 commit comments

Comments
 (0)