@@ -394,6 +394,9 @@ enum class FixKind : uint8_t {
394
394
// / Ignore a type imposed by an assignment destination e.g. `let x: Int = ...`
395
395
IgnoreAssignmentDestinationType,
396
396
397
+ // / Ignore a non-metatype contextual type for a `type(of:)` expression.
398
+ IgnoreNonMetatypeDynamicType,
399
+
397
400
// / Allow argument-to-parameter subtyping even when parameter type
398
401
// / is marked as `inout`.
399
402
AllowConversionThroughInOut,
@@ -2434,6 +2437,30 @@ class IgnoreAssignmentDestinationType final : public ContextualMismatch {
2434
2437
}
2435
2438
};
2436
2439
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
+
2437
2464
// / If this is an argument-to-parameter conversion which is associated with
2438
2465
// / `inout` parameter, subtyping is not permitted, types have to
2439
2466
// / be identical.
0 commit comments