@@ -6012,15 +6012,16 @@ ConstraintSystem::simplifyApplicableFnConstraint(
6012
6012
}
6013
6013
}
6014
6014
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:
6018
6018
// - Generating constraints for `mutating func callAsFunction`. The nominal
6019
6019
// type (`type2`) should be an lvalue type.
6020
6020
// - Extending `Optional` itself with `func callAsFunction` or
6021
6021
// `@dynamicCallable` functionality. Optional types are stripped below if
6022
6022
// `shouldAttemptFixes()` is true.
6023
- auto *origType2 = type2->getDesugaredType ();
6023
+ auto origLValueType2 =
6024
+ getFixedTypeRecursive (type2, flags, /* wantRValue=*/ false );
6024
6025
// Drill down to the concrete type on the right hand side.
6025
6026
type2 = getFixedTypeRecursive (type2, flags, /* wantRValue=*/ true );
6026
6027
auto desugar2 = type2->getDesugaredType ();
@@ -6104,10 +6105,10 @@ ConstraintSystem::simplifyApplicableFnConstraint(
6104
6105
outerLocator.withPathElement (ConstraintLocator::Member));
6105
6106
// Add a `callAsFunction` member constraint, binding the member type to a
6106
6107
// 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 ),
6111
6112
memberTy, DC, FunctionRefKind::SingleApply,
6112
6113
/* outerAlternatives*/ {}, locator);
6113
6114
// Add new applicable function constraint based on the member type
@@ -6117,6 +6118,8 @@ ConstraintSystem::simplifyApplicableFnConstraint(
6117
6118
return SolutionKind::Solved;
6118
6119
}
6119
6120
6121
+ // Record the second type before unwrapping optionals.
6122
+ auto origType2 = desugar2;
6120
6123
unsigned unwrapCount = 0 ;
6121
6124
if (shouldAttemptFixes ()) {
6122
6125
// If we have an optional type, try forcing it to see if that
0 commit comments