@@ -2331,6 +2331,44 @@ class ConstraintSystem {
2331
2331
ConstraintLocatorBuilder locator);
2332
2332
2333
2333
public:
2334
+ // Build a disjunction for the choices between an Optional type and
2335
+ // it's underlying type. We'll make the choice of the Optional
2336
+ // preferred, and select that if the expression type-checks
2337
+ // appropriately with that type.
2338
+ void buildDisjunctionForImplicitlyUnwrappedOptional (
2339
+ TypeVariableType *tv, Type type, ConstraintLocator *locator) {
2340
+
2341
+ // Create the constraint to bind to the optional type and make it
2342
+ // the favored choice.
2343
+ auto *bindToOptional =
2344
+ Constraint::create (*this , ConstraintKind::Bind, tv, type, locator);
2345
+ bindToOptional->setFavored ();
2346
+
2347
+ Type underlyingType;
2348
+
2349
+ // FIXME: Support unwrapping results of function calls.
2350
+ assert (!type->is <AnyFunctionType>());
2351
+
2352
+ underlyingType = type->getWithoutSpecifierType ()->getAnyOptionalObjectType ();
2353
+ assert (underlyingType);
2354
+
2355
+ if (type->is <LValueType>())
2356
+ underlyingType = LValueType::get (underlyingType);
2357
+ else if (type->is <InOutType>())
2358
+ underlyingType = InOutType::get (underlyingType);
2359
+
2360
+ // Create the constraint to bind to the underlying type.
2361
+ auto *bindToUnderlying = Constraint::create (*this , ConstraintKind::Bind, tv,
2362
+ underlyingType, locator);
2363
+
2364
+ llvm::SmallVector<Constraint *, 2 > choices = {bindToOptional,
2365
+ bindToUnderlying};
2366
+
2367
+ // Create the disjunction
2368
+ addDisjunctionConstraint (choices, locator, RememberChoice);
2369
+ }
2370
+
2371
+
2334
2372
// / \brief Resolve the given overload set to the given choice.
2335
2373
void resolveOverload (ConstraintLocator *locator, Type boundType,
2336
2374
OverloadChoice choice, DeclContext *useDC);
0 commit comments