@@ -2077,6 +2077,44 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
2077
2077
llvm_unreachable (" covered switch" );
2078
2078
}
2079
2079
2080
+ static ConstraintFix *fixPropertyWrapperFailure (
2081
+ ConstraintSystem &cs, Type baseTy, Expr *anchor, ConstraintLocator *locator,
2082
+ llvm::function_ref<bool (ResolvedOverloadSetListItem *, VarDecl *, Type)>
2083
+ attemptFix,
2084
+ Optional<Type> toType = None) {
2085
+ auto resolvedOverload = cs.findSelectedOverloadFor (anchor);
2086
+ if (!resolvedOverload)
2087
+ return nullptr ;
2088
+
2089
+ if (auto storageWrapper =
2090
+ cs.getStorageWrapperInformation (resolvedOverload)) {
2091
+ if (attemptFix (resolvedOverload, storageWrapper->first ,
2092
+ storageWrapper->second ))
2093
+ return UsePropertyWrapper::create (
2094
+ cs, storageWrapper->first ,
2095
+ /* usingStorageWrapper=*/ true , baseTy,
2096
+ toType.getValueOr (storageWrapper->second ), locator);
2097
+ }
2098
+
2099
+ if (auto wrapper = cs.getPropertyWrapperInformation (resolvedOverload)) {
2100
+ if (attemptFix (resolvedOverload, wrapper->first , wrapper->second ))
2101
+ return UsePropertyWrapper::create (
2102
+ cs, wrapper->first ,
2103
+ /* usingStorageWrappeer=*/ false , baseTy,
2104
+ toType.getValueOr (wrapper->second ), locator);
2105
+ }
2106
+
2107
+ if (auto wrappedProperty =
2108
+ cs.getWrappedPropertyInformation (resolvedOverload)) {
2109
+ if (attemptFix (resolvedOverload, wrappedProperty->first ,
2110
+ wrappedProperty->second ))
2111
+ return UseWrappedValue::create (
2112
+ cs, wrappedProperty->first , baseTy,
2113
+ toType.getValueOr (wrappedProperty->second ), locator);
2114
+ }
2115
+ return nullptr ;
2116
+ }
2117
+
2080
2118
// / Attempt to repair typing failures and record fixes if needed.
2081
2119
// / \return true if at least some of the failures has been repaired
2082
2120
// / successfully, which allows type matcher to continue.
@@ -2185,13 +2223,31 @@ bool ConstraintSystem::repairFailures(
2185
2223
switch (elt.getKind ()) {
2186
2224
case ConstraintLocator::LValueConversion:
2187
2225
case ConstraintLocator::ApplyArgToParam: {
2226
+ auto loc = getConstraintLocator (locator);
2188
2227
if (repairByInsertingExplicitCall (lhs, rhs))
2189
2228
return true ;
2190
2229
2191
2230
if (lhs->getOptionalObjectType () && !rhs->getOptionalObjectType ()) {
2192
2231
conversionsOrFixes.push_back (
2193
- ForceOptional::create (*this , lhs, lhs->getOptionalObjectType (),
2194
- getConstraintLocator (locator)));
2232
+ ForceOptional::create (*this , lhs, lhs->getOptionalObjectType (), loc));
2233
+ }
2234
+
2235
+ if (elt.getKind () != ConstraintLocator::ApplyArgToParam)
2236
+ break ;
2237
+
2238
+ auto anchor = simplifyLocatorToAnchor (*this , loc);
2239
+
2240
+ if (auto *fix = fixPropertyWrapperFailure (
2241
+ *this , lhs, anchor, loc,
2242
+ [&](ResolvedOverloadSetListItem *overload, VarDecl *decl,
2243
+ Type newBase) {
2244
+ return matchTypes (newBase, rhs, ConstraintKind::Subtype,
2245
+ TypeMatchFlags::TMF_ApplyingFix,
2246
+ overload->Locator )
2247
+ .isSuccess ();
2248
+ },
2249
+ rhs)) {
2250
+ conversionsOrFixes.push_back (fix);
2195
2251
}
2196
2252
break ;
2197
2253
}
@@ -4815,45 +4871,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
4815
4871
if (auto dotExpr =
4816
4872
dyn_cast_or_null<UnresolvedDotExpr>(locator->getAnchor ())) {
4817
4873
auto baseExpr = dotExpr->getBase ();
4818
-
4819
- if (auto resolvedOverload = findSelectedOverloadFor (baseExpr)) {
4820
- if (auto storageWrapper =
4821
- getStorageWrapperInformation (resolvedOverload)) {
4822
- auto wrapperTy = storageWrapper->second ;
4823
- auto result =
4824
- solveWithNewBaseOrName (wrapperTy, member, /* allowFixes=*/ false );
4825
- if (result == SolutionKind::Solved) {
4826
- auto *fix = UsePropertyWrapper::create (*this , storageWrapper->first ,
4827
- /* usingStorageWrapper=*/ true ,
4828
- baseTy, wrapperTy, locator);
4829
- return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
4830
- }
4831
- }
4832
-
4833
- if (auto wrapper = getPropertyWrapperInformation (resolvedOverload)) {
4834
- auto wrapperTy = wrapper->second ;
4835
- auto result =
4836
- solveWithNewBaseOrName (wrapperTy, member, /* allowFixes=*/ false );
4837
- if (result == SolutionKind::Solved) {
4838
- auto *fix = UsePropertyWrapper::create (
4839
- *this , wrapper->first ,
4840
- /* usingStorageWrappeer=*/ false , baseTy, wrapperTy, locator);
4841
- return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
4842
- }
4843
- }
4844
-
4845
- if (auto wrappedProperty =
4846
- getWrappedPropertyInformation (resolvedOverload)) {
4847
- auto wrappedTy = wrappedProperty->second ;
4848
- auto result =
4849
- solveWithNewBaseOrName (wrappedTy, member, /* allowFixes=*/ false );
4850
-
4851
- if (result == SolutionKind::Solved) {
4852
- auto *fix = UseWrappedValue::create (*this , wrappedProperty->first ,
4853
- baseTy, wrappedTy, locator);
4854
- return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
4855
- }
4856
- }
4874
+ if (auto *fix = fixPropertyWrapperFailure (
4875
+ *this , baseTy, baseExpr, locator,
4876
+ [&](ResolvedOverloadSetListItem *overload, VarDecl *decl,
4877
+ Type newBase) {
4878
+ return solveWithNewBaseOrName (newBase, member,
4879
+ /* allowFixes=*/ false ) ==
4880
+ SolutionKind::Solved;
4881
+ })) {
4882
+ return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
4857
4883
}
4858
4884
}
4859
4885
@@ -6806,7 +6832,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
6806
6832
case FixKind::SkipSuperclassRequirement:
6807
6833
case FixKind::ContextualMismatch:
6808
6834
case FixKind::AddMissingArguments:
6809
- case FixKind::SkipUnhandledConstructInFunctionBuilder: {
6835
+ case FixKind::SkipUnhandledConstructInFunctionBuilder:
6836
+ case FixKind::UsePropertyWrapper:
6837
+ case FixKind::UseWrappedValue: {
6810
6838
return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
6811
6839
}
6812
6840
@@ -6827,8 +6855,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
6827
6855
case FixKind::TreatKeyPathSubscriptIndexAsHashable:
6828
6856
case FixKind::AllowInvalidRefInKeyPath:
6829
6857
case FixKind::ExplicitlySpecifyGenericArguments:
6830
- case FixKind::UsePropertyWrapper:
6831
- case FixKind::UseWrappedValue:
6832
6858
case FixKind::GenericArgumentsMismatch:
6833
6859
llvm_unreachable (" handled elsewhere" );
6834
6860
}
0 commit comments