@@ -753,14 +753,6 @@ bool ConstraintSystem::PotentialBindings::infer(
753
753
const ConstraintSystem &cs, llvm::SmallPtrSetImpl<CanType> &exactTypes,
754
754
Constraint *constraint, bool &hasNonDependentMemberRelationalConstraints,
755
755
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
-
764
756
SmallVector<PotentialBinding, 4 > literalBindings;
765
757
766
758
switch (constraint->getKind ()) {
@@ -797,29 +789,29 @@ bool ConstraintSystem::PotentialBindings::infer(
797
789
if (exactTypes.insert (type->getCanonicalType ()).second ) {
798
790
addPotentialBinding (*binding);
799
791
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.
812
794
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
+ }
815
807
816
808
// If this is a type variable representing closure result,
817
809
// which is on the right-side of some relational constraint
818
810
// let's have it try `Void` as well because there is an
819
811
// implicit conversion `() -> T` to `() -> Void` and this
820
812
// 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>() &&
823
815
binding->Kind == AllowedBindingKind::Supertypes &&
824
816
exactTypes.insert (voidType).second ) {
825
817
addPotentialBinding ({voidType, binding->Kind , constraint},
0 commit comments