Skip to content

Commit eb62708

Browse files
committed
[CSFix] Adjust tuple splat fix attempt to record a fix and return a boolean
1 parent 9c196eb commit eb62708

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

lib/Sema/CSFix.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,18 +662,18 @@ bool AllowTupleSplatForSingleParameter::diagnose(Expr *root, bool asNote) const
662662
return false;
663663
}
664664

665-
AllowTupleSplatForSingleParameter *AllowTupleSplatForSingleParameter::attempt(
665+
bool AllowTupleSplatForSingleParameter::attempt(
666666
ConstraintSystem &cs, SmallVectorImpl<Param> &args, ArrayRef<Param> params,
667667
SmallVectorImpl<SmallVector<unsigned, 1>> &bindings,
668668
ConstraintLocatorBuilder locator) {
669669
if (params.size() != 1 || args.size() <= 1)
670-
return nullptr;
670+
return true;
671671

672672
const auto &param = params.front();
673673

674674
auto *paramTy = param.getOldType()->getAs<TupleType>();
675675
if (!paramTy || paramTy->getNumElements() != args.size())
676-
return nullptr;
676+
return true;
677677

678678
SmallVector<TupleTypeElt, 4> argElts;
679679
for (const auto &arg : args) {
@@ -689,6 +689,8 @@ AllowTupleSplatForSingleParameter *AllowTupleSplatForSingleParameter::attempt(
689689
args.clear();
690690
args.push_back(AnyFunctionType::Param(newArgType, param.getLabel()));
691691

692-
return new (cs.getAllocator()) AllowTupleSplatForSingleParameter(
692+
auto *fix = new (cs.getAllocator()) AllowTupleSplatForSingleParameter(
693693
cs, paramTy, cs.getConstraintLocator(locator));
694+
695+
return cs.recordFix(fix);
694696
}

lib/Sema/CSFix.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,11 +1203,13 @@ class AllowTupleSplatForSingleParameter final : public ConstraintFix {
12031203

12041204
bool diagnose(Expr *root, bool asNote = false) const override;
12051205

1206-
static AllowTupleSplatForSingleParameter *
1207-
attempt(ConstraintSystem &cs, SmallVectorImpl<Param> &args,
1208-
ArrayRef<Param> params,
1209-
SmallVectorImpl<SmallVector<unsigned, 1>> &bindings,
1210-
ConstraintLocatorBuilder locator);
1206+
/// Apply this fix to given arguments/parameters and return `true`
1207+
/// this fix is not applicable and solver can't continue, `false`
1208+
/// otherwise.
1209+
static bool attempt(ConstraintSystem &cs, SmallVectorImpl<Param> &args,
1210+
ArrayRef<Param> params,
1211+
SmallVectorImpl<SmallVector<unsigned, 1>> &bindings,
1212+
ConstraintLocatorBuilder locator);
12111213
};
12121214

12131215
} // end namespace constraints

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,8 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
953953
if (!cs.shouldAttemptFixes())
954954
return cs.getTypeMatchFailure(locator);
955955

956-
auto *fix = AllowTupleSplatForSingleParameter::attempt(
957-
cs, argsWithLabels, params, parameterBindings, locator);
958-
959-
if (!fix || cs.recordFix(fix))
956+
if (AllowTupleSplatForSingleParameter::attempt(cs, argsWithLabels, params,
957+
parameterBindings, locator))
960958
return cs.getTypeMatchFailure(locator);
961959
}
962960

0 commit comments

Comments
 (0)