Skip to content

Commit f45654b

Browse files
committed
[CSDiagnostics] Add a diagnostic for pack expansions without pack references
(cherry picked from commit cb2fdd9)
1 parent 4df6ce2 commit f45654b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5422,7 +5422,8 @@ ERROR(cannot_convert_tuple_into_pack_expansion_parameter,none,
54225422
NOTE(cannot_convert_tuple_into_pack_expansion_parameter_note,none,
54235423
"value pack expansion at parameter #%0 expects %1 separate arguments",
54245424
(unsigned, unsigned))
5425-
5425+
ERROR(value_expansion_not_variadic,none,
5426+
"value pack expansion must contain at least one pack reference", ())
54265427

54275428
ERROR(expansion_not_same_shape,none,
54285429
"pack expansion %0 requires that %1 and %2 have the same shape",

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8899,3 +8899,8 @@ bool DestructureTupleToUseWithPackExpansionParameter::diagnoseAsNote() {
88998899
argLoc.getParamIdx(), ParamShape->getNumElements());
89008900
return true;
89018901
}
8902+
8903+
bool ValuePackExpansionWithoutPackReferences::diagnoseAsError() {
8904+
emitDiagnostic(diag::value_expansion_not_variadic);
8905+
return true;
8906+
}

lib/Sema/CSDiagnostics.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,23 @@ class DestructureTupleToUseWithPackExpansionParameter final
30003000
bool diagnoseAsNote() override;
30013001
};
30023002

3003+
/// Diagnose situations when value pack expansion doesn't have any pack
3004+
/// references i.e.:
3005+
///
3006+
/// ```swift
3007+
/// func test(x: Int) {
3008+
/// repeat x
3009+
/// }
3010+
/// ```
3011+
class ValuePackExpansionWithoutPackReferences final : public FailureDiagnostic {
3012+
public:
3013+
ValuePackExpansionWithoutPackReferences(const Solution &solution,
3014+
ConstraintLocator *locator)
3015+
: FailureDiagnostic(solution, locator) {}
3016+
3017+
bool diagnoseAsError() override;
3018+
};
3019+
30033020
} // end namespace constraints
30043021
} // end namespace swift
30053022

0 commit comments

Comments
 (0)