@@ -4542,6 +4542,59 @@ Type Solution::resolveInterfaceType(Type type) const {
4542
4542
4543
4543
Optional<FunctionArgApplyInfo>
4544
4544
Solution::getFunctionArgApplyInfo (ConstraintLocator *locator) const {
4545
+ auto &cs = getConstraintSystem ();
4546
+
4547
+ // It's only valid to use `&` in argument positions, but we need
4548
+ // to figure out exactly where it was used.
4549
+ if (auto *argExpr = getAsExpr<InOutExpr>(locator->getAnchor ())) {
4550
+ auto *argList = cs.getParentExpr (argExpr);
4551
+ assert (argList);
4552
+
4553
+ // `inout` expression might be wrapped in a number of
4554
+ // parens e.g. `test(((&x)))`.
4555
+ if (isa<ParenExpr>(argList)) {
4556
+ for (;;) {
4557
+ auto nextParent = cs.getParentExpr (argList);
4558
+ assert (nextParent && " Incorrect use of `inout` expression" );
4559
+
4560
+ // e.g. `test((&x), x: ...)`
4561
+ if (isa<TupleExpr>(nextParent)) {
4562
+ argList = nextParent;
4563
+ break ;
4564
+ }
4565
+
4566
+ // e.g. `test(((&x)))`
4567
+ if (isa<ParenExpr>(nextParent)) {
4568
+ argList = nextParent;
4569
+ continue ;
4570
+ }
4571
+
4572
+ break ;
4573
+ }
4574
+ }
4575
+
4576
+ unsigned argIdx = 0 ;
4577
+ if (auto *tuple = dyn_cast<TupleExpr>(argList)) {
4578
+ auto arguments = tuple->getElements ();
4579
+
4580
+ for (auto idx : indices (arguments)) {
4581
+ if (arguments[idx]->getSemanticsProvidingExpr () == argExpr) {
4582
+ argIdx = idx;
4583
+ break ;
4584
+ }
4585
+ }
4586
+ }
4587
+
4588
+ auto *call = cs.getParentExpr (argList);
4589
+ assert (call);
4590
+
4591
+ ParameterTypeFlags flags;
4592
+ locator = cs.getConstraintLocator (
4593
+ call, {ConstraintLocator::ApplyArgument,
4594
+ LocatorPathElt::ApplyArgToParam (argIdx, argIdx,
4595
+ flags.withInOut (true ))});
4596
+ }
4597
+
4545
4598
auto anchor = locator->getAnchor ();
4546
4599
auto path = locator->getPath ();
4547
4600
@@ -4635,7 +4688,6 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
4635
4688
auto argIdx = applyArgElt->getArgIdx ();
4636
4689
auto paramIdx = applyArgElt->getParamIdx ();
4637
4690
4638
- auto &cs = getConstraintSystem ();
4639
4691
return FunctionArgApplyInfo (cs.getParentExpr (argExpr), argExpr, argIdx,
4640
4692
simplifyType (getType (argExpr)), paramIdx,
4641
4693
fnInterfaceType, fnType, callee);
0 commit comments