Skip to content

Commit 118631a

Browse files
committed
[ConstraintSystem] NFC: Warn if result of generate* is unused
Not checking success of constraint generation could lead to crashes e.g. when follow-up code accesses something that hasn't been processed due to error. (cherry picked from commit b0f7aef)
1 parent 6fff1c4 commit 118631a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,6 +4544,7 @@ class ConstraintSystem {
45444544
/// Generate constraints for the given solution target.
45454545
///
45464546
/// \returns true if an error occurred, false otherwise.
4547+
LLVM_NODISCARD
45474548
bool generateConstraints(SolutionApplicationTarget &target,
45484549
FreeTypeVariableBinding allowFreeTypeVariables);
45494550

@@ -4552,18 +4553,21 @@ class ConstraintSystem {
45524553
/// \param closure the closure expression
45534554
///
45544555
/// \returns \c true if constraint generation failed, \c false otherwise
4556+
LLVM_NODISCARD
45554557
bool generateConstraints(ClosureExpr *closure);
45564558

45574559
/// Generate constraints for the given (unchecked) expression.
45584560
///
45594561
/// \returns a possibly-sanitized expression, or null if an error occurred.
4562+
LLVM_NODISCARD
45604563
Expr *generateConstraints(Expr *E, DeclContext *dc,
45614564
bool isInputExpression = true);
45624565

45634566
/// Generate constraints for binding the given pattern to the
45644567
/// value of the given expression.
45654568
///
45664569
/// \returns a possibly-sanitized initializer, or null if an error occurred.
4570+
LLVM_NODISCARD
45674571
Type generateConstraints(Pattern *P, ConstraintLocatorBuilder locator,
45684572
bool bindPatternVarsOneWay,
45694573
PatternBindingDecl *patternBinding,
@@ -4573,6 +4577,7 @@ class ConstraintSystem {
45734577
///
45744578
/// \returns true if there was an error in constraint generation, false
45754579
/// if generation succeeded.
4580+
LLVM_NODISCARD
45764581
bool generateConstraints(StmtCondition condition, DeclContext *dc);
45774582

45784583
/// Generate constraints for a case statement.
@@ -4582,6 +4587,7 @@ class ConstraintSystem {
45824587
///
45834588
/// \returns true if there was an error in constraint generation, false
45844589
/// if generation succeeded.
4590+
LLVM_NODISCARD
45854591
bool generateConstraints(CaseStmt *caseStmt, DeclContext *dc,
45864592
Type subjectType, ConstraintLocator *locator);
45874593

@@ -4625,6 +4631,7 @@ class ConstraintSystem {
46254631
/// \param propertyType The type of the wrapped property.
46264632
///
46274633
/// \returns true if there is an error.
4634+
LLVM_NODISCARD
46284635
bool generateWrappedPropertyTypeConstraints(VarDecl *wrappedVar,
46294636
Type initializerType,
46304637
Type propertyType);

0 commit comments

Comments
 (0)