@@ -295,6 +295,13 @@ enum class FixKind : uint8_t {
295295 // / Ignore result builder body if it has `return` statements.
296296 IgnoreResultBuilderWithReturnStmts,
297297
298+ // / Ignore `ErrorExpr` or `ErrorType` during pre-check.
299+ IgnoreInvalidASTNode,
300+
301+ // / Ignore a named pattern whose type we couldn't infer. This issue should
302+ // / already have been diagnosed elsewhere.
303+ IgnoreInvalidNamedPattern,
304+
298305 // / Resolve type of `nil` by providing a contextual type.
299306 SpecifyContextualTypeForNil,
300307
@@ -707,6 +714,26 @@ class ContextualMismatch : public ConstraintFix {
707714
708715 bool diagnose (const Solution &solution, bool asNote = false ) const override ;
709716
717+ bool coalesceAndDiagnose (const Solution &solution,
718+ ArrayRef<ConstraintFix *> secondaryFixes,
719+ bool asNote = false ) const override {
720+ // If the from type or to type is a placeholer type that corresponds to an
721+ // ErrorExpr, the issue has already been diagnosed. There's no need to
722+ // produce another diagnostic for the contextual mismatch complainting that
723+ // a type is not convertible to a placeholder type.
724+ if (auto fromPlaceholder = getFromType ()->getAs <PlaceholderType>()) {
725+ if (fromPlaceholder->getOriginator ().is <ErrorExpr *>()) {
726+ return true ;
727+ }
728+ }
729+ if (auto toPlaceholder = getToType ()->getAs <PlaceholderType>()) {
730+ if (toPlaceholder->getOriginator ().is <ErrorExpr *>()) {
731+ return true ;
732+ }
733+ }
734+ return ConstraintFix::coalesceAndDiagnose (solution, secondaryFixes, asNote);
735+ }
736+
710737 bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override ;
711738
712739 static ContextualMismatch *create (ConstraintSystem &cs, Type lhs, Type rhs,
@@ -2693,6 +2720,57 @@ class IgnoreResultBuilderWithReturnStmts final
26932720 }
26942721};
26952722
2723+ class IgnoreInvalidASTNode final : public ConstraintFix {
2724+ IgnoreInvalidASTNode (ConstraintSystem &cs, ConstraintLocator *locator)
2725+ : IgnoreInvalidASTNode(cs, FixKind::IgnoreInvalidASTNode, locator) {}
2726+
2727+ protected:
2728+ IgnoreInvalidASTNode (ConstraintSystem &cs, FixKind kind,
2729+ ConstraintLocator *locator)
2730+ : ConstraintFix(cs, kind, locator) {}
2731+
2732+ public:
2733+ std::string getName () const override { return " ignore invalid AST node" ; }
2734+
2735+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
2736+
2737+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
2738+ return diagnose (*commonFixes.front ().first );
2739+ }
2740+
2741+ static IgnoreInvalidASTNode *create (ConstraintSystem &cs,
2742+ ConstraintLocator *locator);
2743+
2744+ static bool classof (ConstraintFix *fix) {
2745+ return fix->getKind () == FixKind::IgnoreInvalidASTNode;
2746+ }
2747+ };
2748+
2749+ class IgnoreInvalidNamedPattern final : public ConstraintFix {
2750+ IgnoreInvalidNamedPattern (ConstraintSystem &cs, NamedPattern *pattern,
2751+ ConstraintLocator *locator)
2752+ : ConstraintFix(cs, FixKind::IgnoreInvalidNamedPattern, locator) {}
2753+
2754+ public:
2755+ std::string getName () const override {
2756+ return " specify type for pattern match" ;
2757+ }
2758+
2759+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
2760+
2761+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
2762+ return diagnose (*commonFixes.front ().first );
2763+ }
2764+
2765+ static IgnoreInvalidNamedPattern *create (ConstraintSystem &cs,
2766+ NamedPattern *pattern,
2767+ ConstraintLocator *locator);
2768+
2769+ static bool classof (ConstraintFix *fix) {
2770+ return fix->getKind () == FixKind::IgnoreInvalidNamedPattern;
2771+ }
2772+ };
2773+
26962774class SpecifyContextualTypeForNil final : public ConstraintFix {
26972775 SpecifyContextualTypeForNil (ConstraintSystem &cs,
26982776 ConstraintLocator *locator)
0 commit comments