Skip to content

Commit 2e51e96

Browse files
committed
[CSStep] Don't skip bindings inferred from defaults in diagnostic mode
Helps to diagnose some situations i.e. for-in loops where holes would be propagated to the sequence otherwise.
1 parent c0e09cb commit 2e51e96

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/Sema/CSStep.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,14 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
632632
bool attempt(const TypeVariableBinding &choice) override;
633633

634634
bool shouldSkip(const TypeVariableBinding &choice) const override {
635+
// Let's always attempt types inferred from "defaultable" constraints
636+
// in diagnostic mode. This allows the solver to attempt i.e. `Any`
637+
// for collection literals and produce better diagnostics for for-in
638+
// statements like `for (x, y, z) in [] { ... }` when pattern type
639+
// could not be inferred.
640+
if (CS.shouldAttemptFixes())
641+
return false;
642+
635643
// If this is a defaultable binding and we have found solutions,
636644
// don't explore the default binding.
637645
return AnySolved && choice.isDefaultable();

0 commit comments

Comments
 (0)