@@ -753,14 +753,6 @@ bool ConstraintSystem::PotentialBindings::infer(
753753 const ConstraintSystem &cs, llvm::SmallPtrSetImpl<CanType> &exactTypes,
754754 Constraint *constraint, bool &hasNonDependentMemberRelationalConstraints,
755755 bool &hasDependentMemberRelationalConstraints) {
756- // Determines whether this type variable represents an object
757- // of the optional type extracted by force unwrap.
758- bool isOptionalObject = false ;
759- if (auto *locator = TypeVar->getImpl ().getLocator ()) {
760- auto anchor = locator->getAnchor ();
761- isOptionalObject = isExpr<ForceValueExpr>(anchor);
762- }
763-
764756 SmallVector<PotentialBinding, 4 > literalBindings;
765757
766758 switch (constraint->getKind ()) {
@@ -797,29 +789,29 @@ bool ConstraintSystem::PotentialBindings::infer(
797789 if (exactTypes.insert (type->getCanonicalType ()).second ) {
798790 addPotentialBinding (*binding);
799791
800- // Result of force unwrap is always connected to its base
801- // optional type via `OptionalObject` constraint which
802- // preserves l-valueness, so in case where object type got
803- // inferred before optional type (because it got the
804- // type from context e.g. parameter type of a function call),
805- // we need to test type with and without l-value after
806- // delaying bindings for as long as possible.
807- if (isOptionalObject && !type->is <LValueType>()) {
808- addPotentialBinding (binding->withType (LValueType::get (type)));
809- FullyBound = true ;
810- }
811-
792+ // Determines whether this type variable represents an object
793+ // of the optional type extracted by force unwrap.
812794 if (auto *locator = TypeVar->getImpl ().getLocator ()) {
813- auto path = locator->getPath ();
814- auto voidType = cs.getASTContext ().TheEmptyTupleType ;
795+ auto anchor = locator->getAnchor ();
796+ // Result of force unwrap is always connected to its base
797+ // optional type via `OptionalObject` constraint which
798+ // preserves l-valueness, so in case where object type got
799+ // inferred before optional type (because it got the
800+ // type from context e.g. parameter type of a function call),
801+ // we need to test type with and without l-value after
802+ // delaying bindings for as long as possible.
803+ if (isExpr<ForceValueExpr>(anchor) && !type->is <LValueType>()) {
804+ addPotentialBinding (binding->withType (LValueType::get (type)));
805+ FullyBound = true ;
806+ }
815807
816808 // If this is a type variable representing closure result,
817809 // which is on the right-side of some relational constraint
818810 // let's have it try `Void` as well because there is an
819811 // implicit conversion `() -> T` to `() -> Void` and this
820812 // helps to avoid creating a thunk to support it.
821- if (!path. empty () &&
822- path. back (). getKind () == ConstraintLocator ::ClosureResult &&
813+ auto voidType = cs. getASTContext (). TheEmptyTupleType ;
814+ if (locator-> isLastElement <LocatorPathElt ::ClosureResult>() &&
823815 binding->Kind == AllowedBindingKind::Supertypes &&
824816 exactTypes.insert (voidType).second ) {
825817 addPotentialBinding ({voidType, binding->Kind , constraint},
0 commit comments