2525#include " swift/AST/Types.h"
2626#include " swift/Basic/Debug.h"
2727#include " swift/Sema/ConstraintLocator.h"
28+ #include " swift/Sema/FixBehavior.h"
2829#include " llvm/ADT/ArrayRef.h"
2930#include " llvm/ADT/SmallVector.h"
3031#include " llvm/Support/TrailingObjects.h"
@@ -410,13 +411,12 @@ class ConstraintFix {
410411 ConstraintLocator *Locator;
411412
412413 // / The behavior limit to apply to the diagnostics emitted.
413- DiagnosticBehavior behaviorLimit ;
414+ FixBehavior fixBehavior ;
414415
415416public:
416417 ConstraintFix (ConstraintSystem &cs, FixKind kind, ConstraintLocator *locator,
417- DiagnosticBehavior behaviorLimit =
418- DiagnosticBehavior::Unspecified)
419- : CS(cs), Kind(kind), Locator(locator), behaviorLimit(behaviorLimit) {}
418+ FixBehavior fixBehavior = FixBehavior::Error)
419+ : CS(cs), Kind(kind), Locator(locator), fixBehavior(fixBehavior) {}
420420
421421 virtual ~ConstraintFix ();
422422
@@ -427,14 +427,36 @@ class ConstraintFix {
427427
428428 FixKind getKind () const { return Kind; }
429429
430- bool isWarning () const {
431- return behaviorLimit == DiagnosticBehavior::Warning ||
432- behaviorLimit == DiagnosticBehavior::Ignore;
430+ // / Whether it is still possible to "apply" a solution containing this kind
431+ // / of fix to get a usable AST.
432+ bool canApplySolution () const {
433+ switch (fixBehavior) {
434+ case FixBehavior::AlwaysWarning:
435+ case FixBehavior::DowngradeToWarning:
436+ case FixBehavior::Suppress:
437+ return true ;
438+
439+ case FixBehavior::Error:
440+ return false ;
441+ }
442+ }
443+
444+ // / Whether this kind of fix affects the solution score.
445+ bool affectsSolutionScore () const {
446+ switch (fixBehavior) {
447+ case FixBehavior::AlwaysWarning:
448+ case FixBehavior::DowngradeToWarning:
449+ case FixBehavior::Suppress:
450+ return false ;
451+
452+ case FixBehavior::Error:
453+ return true ;
454+ }
433455 }
434456
435457 // / The diagnostic behavior limit that will be applied to any emitted
436458 // / diagnostics.
437- DiagnosticBehavior diagBehaviorLimit () const { return behaviorLimit ; }
459+ FixBehavior diagfixBehavior () const { return fixBehavior ; }
438460
439461 virtual std::string getName () const = 0;
440462
@@ -680,16 +702,15 @@ class ContextualMismatch : public ConstraintFix {
680702
681703 ContextualMismatch (ConstraintSystem &cs, Type lhs, Type rhs,
682704 ConstraintLocator *locator,
683- DiagnosticBehavior behaviorLimit )
684- : ConstraintFix(cs, FixKind::ContextualMismatch, locator, behaviorLimit ),
705+ FixBehavior fixBehavior )
706+ : ConstraintFix(cs, FixKind::ContextualMismatch, locator, fixBehavior ),
685707 LHS (lhs), RHS(rhs) {}
686708
687709protected:
688710 ContextualMismatch (ConstraintSystem &cs, FixKind kind, Type lhs, Type rhs,
689711 ConstraintLocator *locator,
690- DiagnosticBehavior behaviorLimit =
691- DiagnosticBehavior::Unspecified)
692- : ConstraintFix(cs, kind, locator, behaviorLimit), LHS(lhs), RHS(rhs) {}
712+ FixBehavior fixBehavior = FixBehavior::Error)
713+ : ConstraintFix(cs, kind, locator, fixBehavior), LHS(lhs), RHS(rhs) {}
693714
694715public:
695716 std::string getName () const override { return " fix contextual mismatch" ; }
@@ -777,9 +798,9 @@ class MarkExplicitlyEscaping final : public ContextualMismatch {
777798class MarkGlobalActorFunction final : public ContextualMismatch {
778799 MarkGlobalActorFunction (ConstraintSystem &cs, Type lhs, Type rhs,
779800 ConstraintLocator *locator,
780- DiagnosticBehavior behaviorLimit )
801+ FixBehavior fixBehavior )
781802 : ContextualMismatch(cs, FixKind::MarkGlobalActorFunction, lhs, rhs,
782- locator, behaviorLimit ) {
803+ locator, fixBehavior ) {
783804 }
784805
785806public:
@@ -789,7 +810,7 @@ class MarkGlobalActorFunction final : public ContextualMismatch {
789810
790811 static MarkGlobalActorFunction *create (ConstraintSystem &cs, Type lhs,
791812 Type rhs, ConstraintLocator *locator,
792- DiagnosticBehavior behaviorLimit );
813+ FixBehavior fixBehavior );
793814
794815 static bool classof (ConstraintFix *fix) {
795816 return fix->getKind () == FixKind::MarkGlobalActorFunction;
@@ -825,9 +846,9 @@ class ForceOptional final : public ContextualMismatch {
825846class AddSendableAttribute final : public ContextualMismatch {
826847 AddSendableAttribute (ConstraintSystem &cs, FunctionType *fromType,
827848 FunctionType *toType, ConstraintLocator *locator,
828- DiagnosticBehavior behaviorLimit )
849+ FixBehavior fixBehavior )
829850 : ContextualMismatch(cs, FixKind::AddSendableAttribute, fromType, toType,
830- locator, behaviorLimit ) {
851+ locator, fixBehavior ) {
831852 assert (fromType->isSendable () != toType->isSendable ());
832853 }
833854
@@ -840,7 +861,7 @@ class AddSendableAttribute final : public ContextualMismatch {
840861 FunctionType *fromType,
841862 FunctionType *toType,
842863 ConstraintLocator *locator,
843- DiagnosticBehavior behaviorLimit );
864+ FixBehavior fixBehavior );
844865
845866 static bool classof (ConstraintFix *fix) {
846867 return fix->getKind () == FixKind::AddSendableAttribute;
@@ -1403,11 +1424,14 @@ class AllowTypeOrInstanceMember final : public AllowInvalidMemberRef {
14031424};
14041425
14051426class AllowInvalidPartialApplication final : public ConstraintFix {
1427+ bool isWarning;
1428+
14061429 AllowInvalidPartialApplication (bool isWarning, ConstraintSystem &cs,
14071430 ConstraintLocator *locator)
14081431 : ConstraintFix(cs, FixKind::AllowInvalidPartialApplication, locator,
1409- isWarning ? DiagnosticBehavior::Warning
1410- : DiagnosticBehavior::Unspecified) {}
1432+ isWarning ? FixBehavior::AlwaysWarning
1433+ : FixBehavior::Error),
1434+ isWarning (isWarning) {}
14111435
14121436public:
14131437 std::string getName () const override {
@@ -2141,10 +2165,9 @@ class AllowArgumentMismatch : public ContextualMismatch {
21412165
21422166 AllowArgumentMismatch (ConstraintSystem &cs, FixKind kind, Type argType,
21432167 Type paramType, ConstraintLocator *locator,
2144- DiagnosticBehavior behaviorLimit =
2145- DiagnosticBehavior::Unspecified)
2168+ FixBehavior fixBehavior = FixBehavior::Error)
21462169 : ContextualMismatch(
2147- cs, kind, argType, paramType, locator, behaviorLimit ) {}
2170+ cs, kind, argType, paramType, locator, fixBehavior ) {}
21482171
21492172public:
21502173 std::string getName () const override {
@@ -2292,9 +2315,9 @@ class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch {
22922315 TreatEphemeralAsNonEphemeral (ConstraintSystem &cs, ConstraintLocator *locator,
22932316 Type srcType, Type dstType,
22942317 ConversionRestrictionKind conversionKind,
2295- DiagnosticBehavior behaviorLimit )
2318+ FixBehavior fixBehavior )
22962319 : AllowArgumentMismatch(cs, FixKind::TreatEphemeralAsNonEphemeral,
2297- srcType, dstType, locator, behaviorLimit ),
2320+ srcType, dstType, locator, fixBehavior ),
22982321 ConversionKind (conversionKind) {}
22992322
23002323public:
@@ -2458,7 +2481,7 @@ class AllowCoercionToForceCast final : public ContextualMismatch {
24582481 AllowCoercionToForceCast (ConstraintSystem &cs, Type fromType, Type toType,
24592482 ConstraintLocator *locator)
24602483 : ContextualMismatch(cs, FixKind::AllowCoercionToForceCast, fromType,
2461- toType, locator, DiagnosticBehavior::Warning ) {}
2484+ toType, locator, FixBehavior::AlwaysWarning ) {}
24622485
24632486public:
24642487 std::string getName () const override {
@@ -2572,7 +2595,7 @@ class SpecifyLabelToAssociateTrailingClosure final : public ConstraintFix {
25722595 SpecifyLabelToAssociateTrailingClosure (ConstraintSystem &cs,
25732596 ConstraintLocator *locator)
25742597 : ConstraintFix(cs, FixKind::SpecifyLabelToAssociateTrailingClosure,
2575- locator, DiagnosticBehavior::Warning ) {}
2598+ locator, FixBehavior::AlwaysWarning ) {}
25762599
25772600public:
25782601 std::string getName () const override {
@@ -2742,7 +2765,7 @@ class SpecifyBaseTypeForOptionalUnresolvedMember final : public ConstraintFix {
27422765 DeclNameRef memberName,
27432766 ConstraintLocator *locator)
27442767 : ConstraintFix(cs, FixKind::SpecifyBaseTypeForOptionalUnresolvedMember,
2745- locator, DiagnosticBehavior::Warning ),
2768+ locator, FixBehavior::AlwaysWarning ),
27462769 MemberName (memberName) {}
27472770 DeclNameRef MemberName;
27482771
@@ -2773,7 +2796,7 @@ class CheckedCastContextualMismatchWarning : public ContextualMismatch {
27732796 CheckedCastKind kind,
27742797 ConstraintLocator *locator)
27752798 : ContextualMismatch(cs, fixKind, fromType, toType, locator,
2776- DiagnosticBehavior::Warning ),
2799+ FixBehavior::AlwaysWarning ),
27772800 CastKind (kind) {}
27782801 CheckedCastKind CastKind;
27792802};
@@ -2932,7 +2955,7 @@ class AllowTupleLabelMismatch final : public ContextualMismatch {
29322955 AllowTupleLabelMismatch (ConstraintSystem &cs, Type fromType, Type toType,
29332956 ConstraintLocator *locator)
29342957 : ContextualMismatch(cs, FixKind::AllowTupleLabelMismatch, fromType,
2935- toType, locator, DiagnosticBehavior::Warning ) {}
2958+ toType, locator, FixBehavior::AlwaysWarning ) {}
29362959
29372960public:
29382961 std::string getName () const override { return " allow tuple label mismatch" ; }
0 commit comments