@@ -2567,7 +2567,7 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
2567
2567
TypeMatchOptions flags,
2568
2568
ConstraintLocatorBuilder locator) {
2569
2569
// Resolve the optional type.
2570
- Type optLValueTy = getFixedTypeRecursive (first, /* wantRValue=*/ false )
2570
+ Type optLValueTy = getFixedTypeRecursive (first, /* wantRValue=*/ false );
2571
2571
Type optTy = optLValueTy->getRValueType ();
2572
2572
if (optTy.getPointer () != optLValueTy.getPointer ())
2573
2573
optTy = getFixedTypeRecursive (optTy, /* wantRValue=*/ false );
@@ -3288,11 +3288,23 @@ ConstraintSystem::simplifyMemberConstraint(ConstraintKind kind,
3288
3288
}
3289
3289
3290
3290
ConstraintSystem::SolutionKind
3291
- ConstraintSystem::simplifyDefaultableConstraint (const Constraint &constraint) {
3292
- auto baseTy = getFixedTypeRecursive (constraint.getFirstType (), true );
3291
+ ConstraintSystem::simplifyDefaultableConstraint (
3292
+ Type first, Type second,
3293
+ TypeMatchOptions flags,
3294
+ ConstraintLocatorBuilder locator) {
3295
+ first = getFixedTypeRecursive (first, true );
3296
+
3297
+ if (first->isTypeVariableOrMember ()) {
3298
+ if (flags.contains (TMF_GenerateConstraints)) {
3299
+ addUnsolvedConstraint (
3300
+ Constraint::create (*this , ConstraintKind::Defaultable, first, second,
3301
+ DeclName (), FunctionRefKind::Compound,
3302
+ getConstraintLocator (locator)));
3303
+ return SolutionKind::Solved;
3304
+ }
3293
3305
3294
- if (baseTy->isTypeVariableOrMember ())
3295
3306
return SolutionKind::Unsolved;
3307
+ }
3296
3308
3297
3309
// Otherwise, any type is fine.
3298
3310
return SolutionKind::Solved;
@@ -4173,9 +4185,10 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
4173
4185
case ConstraintKind::OptionalObject:
4174
4186
return simplifyOptionalObjectConstraint (first, second, subflags, locator);
4175
4187
4176
- case ConstraintKind::Bind: // FIXME: This should go through matchTypes() above
4188
+ case ConstraintKind::Defaultable:
4189
+ return simplifyDefaultableConstraint (first, second, subflags, locator);
4177
4190
4178
- default : {
4191
+ case ConstraintKind::Bind: { // FIXME: This should go through matchTypes() above
4179
4192
// FALLBACK CASE: do the slow thing.
4180
4193
auto c = Constraint::create (*this , kind, first, second, DeclName (),
4181
4194
FunctionRefKind::Compound,
@@ -4189,6 +4202,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
4189
4202
case ConstraintKind::UnresolvedValueMember:
4190
4203
case ConstraintKind::TypeMember:
4191
4204
case ConstraintKind::BindOverload:
4205
+ case ConstraintKind::Disjunction:
4192
4206
llvm_unreachable (" Use the correct addConstraint()" );
4193
4207
}
4194
4208
}
@@ -4316,7 +4330,10 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
4316
4330
constraint.getLocator ());
4317
4331
4318
4332
case ConstraintKind::Defaultable:
4319
- return simplifyDefaultableConstraint (constraint);
4333
+ return simplifyDefaultableConstraint (constraint.getFirstType (),
4334
+ constraint.getSecondType (),
4335
+ TMF_GenerateConstraints,
4336
+ constraint.getLocator ());
4320
4337
4321
4338
case ConstraintKind::Disjunction:
4322
4339
// Disjunction constraints are never solved here.
0 commit comments