@@ -394,6 +394,9 @@ enum class FixKind : uint8_t {
394394 // / Ignore a type imposed by an assignment destination e.g. `let x: Int = ...`
395395 IgnoreAssignmentDestinationType,
396396
397+ // / Ignore a non-metatype contextual type for a `type(of:)` expression.
398+ IgnoreNonMetatypeDynamicType,
399+
397400 // / Allow argument-to-parameter subtyping even when parameter type
398401 // / is marked as `inout`.
399402 AllowConversionThroughInOut,
@@ -2434,6 +2437,30 @@ class IgnoreAssignmentDestinationType final : public ContextualMismatch {
24342437 }
24352438};
24362439
2440+ // / Ignore a non-metatype contextual type for a `type(of:)` expression, for
2441+ // / example `let x: Int = type(of: foo)`.
2442+ class IgnoreNonMetatypeDynamicType final : public ContextualMismatch {
2443+ IgnoreNonMetatypeDynamicType (ConstraintSystem &cs, Type instanceTy,
2444+ Type metatypeTy, ConstraintLocator *locator)
2445+ : ContextualMismatch(cs, FixKind::IgnoreNonMetatypeDynamicType,
2446+ instanceTy, metatypeTy, locator) {}
2447+
2448+ public:
2449+ std::string getName () const override {
2450+ return " ignore non-metatype result for 'type(of:)'" ;
2451+ }
2452+
2453+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
2454+
2455+ static IgnoreNonMetatypeDynamicType *create (ConstraintSystem &cs,
2456+ Type instanceTy, Type metatypeTy,
2457+ ConstraintLocator *locator);
2458+
2459+ static bool classof (const ConstraintFix *fix) {
2460+ return fix->getKind () == FixKind::IgnoreNonMetatypeDynamicType;
2461+ }
2462+ };
2463+
24372464// / If this is an argument-to-parameter conversion which is associated with
24382465// / `inout` parameter, subtyping is not permitted, types have to
24392466// / be identical.
0 commit comments