Skip to content

IUO: Add a method to build a binding disjunction for T? and T. #13719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,44 @@ class ConstraintSystem {
ConstraintLocatorBuilder locator);

public:
// Build a disjunction for the choices between an Optional type and
// it's underlying type. We'll make the choice of the Optional
// preferred, and select that if the expression type-checks
// appropriately with that type.
void buildDisjunctionForImplicitlyUnwrappedOptional(
TypeVariableType *tv, Type type, ConstraintLocator *locator) {

// Create the constraint to bind to the optional type and make it
// the favored choice.
auto *bindToOptional =
Constraint::create(*this, ConstraintKind::Bind, tv, type, locator);
bindToOptional->setFavored();

Type underlyingType;

// FIXME: Support unwrapping results of function calls.
assert(!type->is<AnyFunctionType>());

underlyingType = type->getWithoutSpecifierType()->getAnyOptionalObjectType();
assert(underlyingType);

if (type->is<LValueType>())
underlyingType = LValueType::get(underlyingType);
else if (type->is<InOutType>())
underlyingType = InOutType::get(underlyingType);

// Create the constraint to bind to the underlying type.
auto *bindToUnderlying = Constraint::create(*this, ConstraintKind::Bind, tv,
underlyingType, locator);

llvm::SmallVector<Constraint *, 2> choices = {bindToOptional,
bindToUnderlying};

// Create the disjunction
addDisjunctionConstraint(choices, locator, RememberChoice);
}


/// \brief Resolve the given overload set to the given choice.
void resolveOverload(ConstraintLocator *locator, Type boundType,
OverloadChoice choice, DeclContext *useDC);
Expand Down