@@ -631,35 +631,6 @@ class MemberAccessOnOptionalBaseFailure final : public FailureDiagnostic {
631
631
bool diagnoseAsError () override ;
632
632
};
633
633
634
- // / Diagnose failures related to use of the unwrapped optional types,
635
- // / which require some type of force-unwrap e.g. "!" or "try!".
636
- class MissingOptionalUnwrapFailure final : public FailureDiagnostic {
637
- Type BaseType;
638
- Type UnwrappedType;
639
-
640
- public:
641
- MissingOptionalUnwrapFailure (ConstraintSystem &cs, Type baseType,
642
- Type unwrappedType, ConstraintLocator *locator)
643
- : FailureDiagnostic(cs, locator), BaseType(baseType),
644
- UnwrappedType (unwrappedType) {}
645
-
646
- bool diagnoseAsError () override ;
647
-
648
- private:
649
- Type getBaseType () const {
650
- return resolveType (BaseType, /* reconstituteSugar=*/ true );
651
- }
652
-
653
- Type getUnwrappedType () const {
654
- return resolveType (UnwrappedType, /* reconstituteSugar=*/ true );
655
- }
656
-
657
- // / Suggest a default value via `?? <default value>`
658
- void offerDefaultValueUnwrapFixIt (DeclContext *DC, Expr *expr) const ;
659
- // / Suggest a force optional unwrap via `!`
660
- void offerForceUnwrapFixIt (Expr *expr) const ;
661
- };
662
-
663
634
// / Diagnose errors associated with rvalues in positions
664
635
// / where an lvalue is required, such as inout arguments.
665
636
class RValueTreatedAsLValueFailure final : public FailureDiagnostic {
@@ -852,6 +823,32 @@ class ContextualFailure : public FailureDiagnostic {
852
823
getDiagnosticFor (ContextualTypePurpose context, bool forProtocol);
853
824
};
854
825
826
+ // / Diagnose failures related to use of the unwrapped optional types,
827
+ // / which require some type of force-unwrap e.g. "!" or "try!".
828
+ class MissingOptionalUnwrapFailure final : public ContextualFailure {
829
+ public:
830
+ MissingOptionalUnwrapFailure (ConstraintSystem &cs, Type fromType, Type toType,
831
+ ConstraintLocator *locator)
832
+ : ContextualFailure(cs, fromType, toType, locator) {}
833
+
834
+ bool diagnoseAsError () override ;
835
+
836
+ private:
837
+ Type getBaseType () const {
838
+ return resolveType (getFromType (), /* reconstituteSugar=*/ true );
839
+ }
840
+
841
+ Type getUnwrappedType () const {
842
+ return resolveType (getBaseType ()->getOptionalObjectType (),
843
+ /* reconstituteSugar=*/ true );
844
+ }
845
+
846
+ // / Suggest a default value via `?? <default value>`
847
+ void offerDefaultValueUnwrapFixIt (DeclContext *DC, Expr *expr) const ;
848
+ // / Suggest a force optional unwrap via `!`
849
+ void offerForceUnwrapFixIt (Expr *expr) const ;
850
+ };
851
+
855
852
// / Diagnostics for mismatched generic arguments e.g
856
853
// / ```swift
857
854
// / struct F<G> {}
0 commit comments