Skip to content

Commit fb20a04

Browse files
committed
Address PR comments.
1 parent c9ecd50 commit fb20a04

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ ERROR(attr_differentiable_use_wrt_not_withrespectto,none,
14981498
ERROR(attr_differentiable_missing_label,PointsToFirstBadToken,
14991499
"missing label '%0:' in '@differentiable' attribute", (StringRef))
15001500
ERROR(attr_differentiable_expected_label,none,
1501-
"expected a function specifier label, e.g. 'wrt:', 'jvp:', or 'vjp:'", ())
1501+
"expected either 'wrt:' or a function specifier label, e.g. 'jvp:', "
1502+
"or 'vjp:'", ())
15021503

15031504
// differentiating
15041505
ERROR(attr_differentiating_expected_original_name,PointsToFirstBadToken,

lib/Parse/ParseDecl.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,9 @@ bool Parser::parseDifferentiableAttributeArguments(
957957
diagnose(Tok, diag::unexpected_separator, ",");
958958
return true;
959959
}
960-
// Check that token after comma is a function specifier label.
961-
if (!Tok.is(tok::identifier) || !(Tok.getText() == "jvp" ||
960+
// Check that token after comma is 'wrt:' or a function specifier label.
961+
if (!Tok.is(tok::identifier) || !(Tok.getText() == "wrt" ||
962+
Tok.getText() == "jvp" ||
962963
Tok.getText() == "vjp")) {
963964
diagnose(Tok, diag::attr_differentiable_expected_label);
964965
return true;
@@ -971,18 +972,16 @@ bool Parser::parseDifferentiableAttributeArguments(
971972
SyntaxParsingContext ContentContext(
972973
SyntaxContext, SyntaxKind::DifferentiableAttributeArguments);
973974

974-
// Parse optional differentiation parameters, starting with
975-
// the 'linear' label (optinal).
975+
// Parse optional differentiation parameters.
976+
// Parse 'linear' label (optional).
976977
if (Tok.is(tok::identifier) && Tok.getText() == "linear") {
977978
linear = true;
978-
if (consumeIfTrailingComma())
979-
return errorAndSkipToEnd();
980-
consumeToken();
979+
consumeIdentifier();
980+
// If no trailing comma or 'where' clause, terminate parsing arguments.
981981
if (Tok.isNot(tok::comma) && Tok.isNot(tok::kw_where))
982982
return false;
983-
if (Tok.is(tok::comma)) {
984-
consumeToken();
985-
}
983+
if (consumeIfTrailingComma())
984+
return errorAndSkipToEnd();
986985
} else {
987986
linear = false;
988987
}

0 commit comments

Comments
 (0)