@@ -3275,45 +3275,60 @@ ConstraintSystem::simplifyDefaultableConstraint(const Constraint &constraint) {
3275
3275
3276
3276
3277
3277
ConstraintSystem::SolutionKind
3278
- ConstraintSystem::simplifyDynamicTypeOfConstraint (const Constraint &constraint) {
3278
+ ConstraintSystem::simplifyDynamicTypeOfConstraint (
3279
+ Type type1, Type type2,
3280
+ TypeMatchOptions flags,
3281
+ ConstraintLocatorBuilder locator) {
3282
+ TypeMatchOptions subflags = getDefaultDecompositionOptions (flags);
3283
+
3284
+ // Local function to form an unsolved result.
3285
+ auto formUnsolved = [&] {
3286
+ if (flags.contains (TMF_GenerateConstraints)) {
3287
+ addUnsolvedConstraint (
3288
+ Constraint::create (*this , ConstraintKind::DynamicTypeOf, type1, type2,
3289
+ DeclName (), FunctionRefKind::Compound,
3290
+ getConstraintLocator (locator)));
3291
+ return SolutionKind::Solved;
3292
+ }
3293
+
3294
+ return SolutionKind::Unsolved;
3295
+ };
3296
+
3279
3297
// Solve forward.
3280
- Type type2 = getFixedTypeRecursive (constraint.getSecondType (),
3281
- /* wantRValue=*/ true );
3298
+ type2 = getFixedTypeRecursive (type2, /* wantRValue=*/ true );
3282
3299
if (!type2->isTypeVariableOrMember ()) {
3283
3300
Type dynamicType2;
3284
3301
if (type2->isAnyExistentialType ()) {
3285
3302
dynamicType2 = ExistentialMetatypeType::get (type2);
3286
3303
} else {
3287
3304
dynamicType2 = MetatypeType::get (type2);
3288
3305
}
3289
- return matchTypes (constraint.getFirstType (), dynamicType2,
3290
- TypeMatchKind::BindType, TMF_GenerateConstraints,
3291
- constraint.getLocator ());
3306
+ return matchTypes (type1, dynamicType2, TypeMatchKind::BindType, subflags,
3307
+ locator);
3292
3308
}
3293
3309
3294
3310
// Okay, can't solve forward. See what we can do backwards.
3295
- Type type1 = getFixedTypeRecursive (constraint.getFirstType (), true );
3296
-
3311
+ type1 = getFixedTypeRecursive (type1, true );
3297
3312
if (type1->isTypeVariableOrMember ())
3298
- return SolutionKind::Unsolved ;
3313
+ return formUnsolved () ;
3299
3314
3300
3315
// If we have an existential metatype, that's good enough to solve
3301
3316
// the constraint.
3302
3317
if (auto metatype1 = type1->getAs <ExistentialMetatypeType>())
3303
3318
return matchTypes (metatype1->getInstanceType (), type2,
3304
3319
TypeMatchKind::BindType,
3305
- TMF_GenerateConstraints, constraint. getLocator () );
3320
+ subflags, locator );
3306
3321
3307
3322
// If we have a normal metatype, we can't solve backwards unless we
3308
3323
// know what kind of object it is.
3309
3324
if (auto metatype1 = type1->getAs <MetatypeType>()) {
3310
3325
Type instanceType1 = getFixedTypeRecursive (metatype1->getInstanceType (),
3311
3326
true );
3312
- if (! instanceType1->isTypeVariableOrMember ()) {
3313
- return matchTypes (instanceType1, type2,
3314
- TypeMatchKind::BindType,
3315
- TMF_GenerateConstraints, constraint. getLocator ());
3316
- }
3327
+ if (instanceType1->isTypeVariableOrMember ())
3328
+ return formUnsolved ();
3329
+
3330
+ return matchTypes (instanceType1, type2, TypeMatchKind::BindType, subflags,
3331
+ locator);
3317
3332
}
3318
3333
3319
3334
// It's definitely not either kind of metatype, so we can
@@ -4120,6 +4135,9 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
4120
4135
case ConstraintKind::ApplicableFunction:
4121
4136
return simplifyApplicableFnConstraint (first, second, subflags, locator);
4122
4137
4138
+ case ConstraintKind::DynamicTypeOf:
4139
+ return simplifyDynamicTypeOfConstraint (first, second, subflags, locator);
4140
+
4123
4141
case ConstraintKind::Bind: // FIXME: This should go through matchTypes() above
4124
4142
4125
4143
default : {
@@ -4201,7 +4219,10 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
4201
4219
None, constraint.getLocator ());
4202
4220
4203
4221
case ConstraintKind::DynamicTypeOf:
4204
- return simplifyDynamicTypeOfConstraint (constraint);
4222
+ return simplifyDynamicTypeOfConstraint (constraint.getFirstType (),
4223
+ constraint.getSecondType (),
4224
+ None,
4225
+ constraint.getLocator ());
4205
4226
4206
4227
case ConstraintKind::BindOverload:
4207
4228
resolveOverload (constraint.getLocator (), constraint.getFirstType (),
0 commit comments