Skip to content

Commit e0847c5

Browse files
committed
[ConstraintSystem] More cleanup of nil literal handling.
1 parent 56a6360 commit e0847c5

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,31 +310,27 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
310310

311311
// Check whether we can perform this binding.
312312
// FIXME: this has a super-inefficient extraneous simplifyType() in it.
313-
bool isNilLiteral = false;
314-
bool *isNilLiteralPtr = nullptr;
315313
if (auto boundType = checkTypeOfBinding(typeVar, type)) {
316314
type = *boundType;
317315
if (type->hasTypeVariable())
318316
result.InvolvesTypeVariables = true;
319317
} else {
320-
if (!addOptionalSupertypeBindings && kind == AllowedBindingKind::Supertypes)
321-
isNilLiteralPtr = &isNilLiteral;
322-
323-
if (isNilLiteralPtr) {
324-
if (auto *bindingTypeVar =
325-
type->getRValueType()->getAs<TypeVariableType>())
326-
*isNilLiteralPtr = hasNilLiteralConstraint(bindingTypeVar, *this);
327-
else
328-
*isNilLiteralPtr = false;
329-
}
318+
auto *bindingTypeVar = type->getRValueType()->getAs<TypeVariableType>();
330319

331-
// If the bound is a 'nil' literal type, add optional supertype bindings.
332-
if (isNilLiteral) {
333-
addOptionalSupertypeBindings = true;
320+
if (!bindingTypeVar)
334321
return None;
335-
}
336322

337323
result.InvolvesTypeVariables = true;
324+
325+
// If we've already set addOptionalSupertypeBindings, or we aren't
326+
// allowing supertype bindings, we're done.
327+
if (addOptionalSupertypeBindings || kind != AllowedBindingKind::Supertypes)
328+
return None;
329+
330+
// If the bound is a 'nil' literal type, add optional supertype bindings.
331+
if (hasNilLiteralConstraint(bindingTypeVar, *this))
332+
addOptionalSupertypeBindings = true;
333+
338334
return None;
339335
}
340336

0 commit comments

Comments
 (0)