Skip to content

Commit cb2fdd9

Browse files
committed
[CSDiagnostics] Add a diagnostic for pack expansions without pack references
1 parent d8c8a39 commit cb2fdd9

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
@@ -5430,7 +5430,8 @@ ERROR(cannot_convert_tuple_into_pack_expansion_parameter,none,
54305430
NOTE(cannot_convert_tuple_into_pack_expansion_parameter_note,none,
54315431
"value pack expansion at parameter #%0 expects %1 separate arguments",
54325432
(unsigned, unsigned))
5433-
5433+
ERROR(value_expansion_not_variadic,none,
5434+
"value pack expansion must contain at least one pack reference", ())
54345435

54355436
ERROR(expansion_not_same_shape,none,
54365437
"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
@@ -8901,3 +8901,8 @@ bool DestructureTupleToUseWithPackExpansionParameter::diagnoseAsNote() {
89018901
argLoc.getParamIdx(), ParamShape->getNumElements());
89028902
return true;
89038903
}
8904+
8905+
bool ValuePackExpansionWithoutPackReferences::diagnoseAsError() {
8906+
emitDiagnostic(diag::value_expansion_not_variadic);
8907+
return true;
8908+
}

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)