@@ -6012,15 +6012,16 @@ ConstraintSystem::simplifyApplicableFnConstraint(
60126012 }
60136013 }
60146014
6015- // Before stripping lvalue-ness and optional types, save original type for
6016- // handling `func callAsFunction` and `@dynamicCallable` applications.
6017- // This supports the following cases:
6015+ // Before stripping lvalue-ness and optional types, save the original second
6016+ // type for handling `func callAsFunction` and `@dynamicCallable`
6017+ // applications. This supports the following cases:
60186018 // - Generating constraints for `mutating func callAsFunction`. The nominal
60196019 // type (`type2`) should be an lvalue type.
60206020 // - Extending `Optional` itself with `func callAsFunction` or
60216021 // `@dynamicCallable` functionality. Optional types are stripped below if
60226022 // `shouldAttemptFixes()` is true.
6023- auto *origType2 = type2->getDesugaredType ();
6023+ auto origLValueType2 =
6024+ getFixedTypeRecursive (type2, flags, /* wantRValue=*/ false );
60246025 // Drill down to the concrete type on the right hand side.
60256026 type2 = getFixedTypeRecursive (type2, flags, /* wantRValue=*/ true );
60266027 auto desugar2 = type2->getDesugaredType ();
@@ -6104,10 +6105,10 @@ ConstraintSystem::simplifyApplicableFnConstraint(
61046105 outerLocator.withPathElement (ConstraintLocator::Member));
61056106 // Add a `callAsFunction` member constraint, binding the member type to a
61066107 // type variable.
6107- auto memberTy = createTypeVariable (memberLoc, TVO_CanBindToLValue |
6108- TVO_CanBindToNoEscape |
6109- TVO_CanBindToInOut);
6110- addValueMemberConstraint (origType2 , DeclName (ctx.Id_callAsFunction ),
6108+ auto memberTy = createTypeVariable (memberLoc, /* options= */ 0 );
6109+ // TODO: Revisit this if `static func callAsFunction` is to be supported.
6110+ // Static member constraint requires `FunctionRefKind::DoubleApply`.
6111+ addValueMemberConstraint (origLValueType2 , DeclName (ctx.Id_callAsFunction ),
61116112 memberTy, DC, FunctionRefKind::SingleApply,
61126113 /* outerAlternatives*/ {}, locator);
61136114 // Add new applicable function constraint based on the member type
@@ -6117,6 +6118,8 @@ ConstraintSystem::simplifyApplicableFnConstraint(
61176118 return SolutionKind::Solved;
61186119 }
61196120
6121+ // Record the second type before unwrapping optionals.
6122+ auto origType2 = desugar2;
61206123 unsigned unwrapCount = 0 ;
61216124 if (shouldAttemptFixes ()) {
61226125 // If we have an optional type, try forcing it to see if that
0 commit comments