@@ -2562,13 +2562,25 @@ ConstraintSystem::simplifyCheckedCastConstraint(
2562
2562
}
2563
2563
2564
2564
ConstraintSystem::SolutionKind
2565
- ConstraintSystem::simplifyOptionalObjectConstraint (const Constraint &constraint)
2566
- {
2565
+ ConstraintSystem::simplifyOptionalObjectConstraint (
2566
+ Type first, Type second,
2567
+ TypeMatchOptions flags,
2568
+ ConstraintLocatorBuilder locator) {
2567
2569
// Resolve the optional type.
2568
- Type optLValueTy = simplifyType (constraint. getFirstType ());
2570
+ Type optLValueTy = getFixedTypeRecursive (first, /* wantRValue= */ false )
2569
2571
Type optTy = optLValueTy->getRValueType ();
2570
-
2572
+ if (optTy.getPointer () != optLValueTy.getPointer ())
2573
+ optTy = getFixedTypeRecursive (optTy, /* wantRValue=*/ false );
2574
+
2571
2575
if (optTy->isTypeVariableOrMember ()) {
2576
+ if (flags.contains (TMF_GenerateConstraints)) {
2577
+ addUnsolvedConstraint (
2578
+ Constraint::create (*this , ConstraintKind::OptionalObject, optLValueTy,
2579
+ second, DeclName (), FunctionRefKind::Compound,
2580
+ getConstraintLocator (locator)));
2581
+ return SolutionKind::Solved;
2582
+ }
2583
+
2572
2584
return SolutionKind::Unsolved;
2573
2585
}
2574
2586
@@ -2582,9 +2594,7 @@ ConstraintSystem::simplifyOptionalObjectConstraint(const Constraint &constraint)
2582
2594
objectTy = LValueType::get (objectTy);
2583
2595
2584
2596
// Equate it to the other type in the constraint.
2585
- addConstraint (ConstraintKind::Bind, objectTy, constraint.getSecondType (),
2586
- constraint.getLocator ());
2587
-
2597
+ addConstraint (ConstraintKind::Bind, objectTy, second, locator);
2588
2598
return SolutionKind::Solved;
2589
2599
}
2590
2600
@@ -4160,6 +4170,9 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
4160
4170
case ConstraintKind::CheckedCast:
4161
4171
return simplifyCheckedCastConstraint (first, second, subflags, locator);
4162
4172
4173
+ case ConstraintKind::OptionalObject:
4174
+ return simplifyOptionalObjectConstraint (first, second, subflags, locator);
4175
+
4163
4176
case ConstraintKind::Bind: // FIXME: This should go through matchTypes() above
4164
4177
4165
4178
default : {
@@ -4286,7 +4299,10 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
4286
4299
}
4287
4300
4288
4301
case ConstraintKind::OptionalObject:
4289
- return simplifyOptionalObjectConstraint (constraint);
4302
+ return simplifyOptionalObjectConstraint (constraint.getFirstType (),
4303
+ constraint.getSecondType (),
4304
+ TMF_GenerateConstraints,
4305
+ constraint.getLocator ());
4290
4306
4291
4307
case ConstraintKind::ValueMember:
4292
4308
case ConstraintKind::UnresolvedValueMember:
0 commit comments