@@ -1244,72 +1244,63 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
12441244 return *member;
12451245}
12461246
1247- static std::optional<std::pair<VarDecl *, Type>>
1248- getPropertyWrapperInformationFromOverload (
1249- SelectedOverload resolvedOverload, DeclContext *DC,
1250- llvm::function_ref<std::optional<std::pair<VarDecl *, Type>>(VarDecl *)>
1251- getInformation) {
1252- if (auto *decl =
1253- dyn_cast_or_null<VarDecl>(resolvedOverload.choice .getDeclOrNull ())) {
1254- if (auto declInformation = getInformation (decl)) {
1255- Type type;
1256- VarDecl *memberDecl;
1257- std::tie (memberDecl, type) = *declInformation;
1258- if (Type baseType = resolvedOverload.choice .getBaseType ()) {
1259- type = baseType->getRValueType ()->getTypeOfMember (memberDecl, type);
1260- }
1261- return std::make_pair (decl, type);
1262- }
1263- }
1264- return std::nullopt ;
1265- }
1247+ static Type getPropertyWrapperTypeFromOverload (
1248+ ConstraintSystem &cs, SelectedOverload resolvedOverload,
1249+ llvm::function_ref<VarDecl *(VarDecl *)> getWrapperVar) {
1250+ auto *D = dyn_cast_or_null<VarDecl>(resolvedOverload.choice .getDeclOrNull ());
1251+ if (!D)
1252+ return Type ();
12661253
1267- std::optional<std::pair<VarDecl *, Type>>
1268- ConstraintSystem::getPropertyWrapperProjectionInfo (
1269- SelectedOverload resolvedOverload) {
1270- return getPropertyWrapperInformationFromOverload (
1271- resolvedOverload, DC,
1272- [](VarDecl *decl) -> std::optional<std::pair<VarDecl *, Type>> {
1273- if (!decl->hasAttachedPropertyWrapper ())
1274- return std::nullopt ;
1254+ auto *wrapperVar = getWrapperVar (D);
1255+ if (!wrapperVar)
1256+ return Type ();
12751257
1276- auto projectionVar = decl->getPropertyWrapperProjectionVar ();
1277- if (!projectionVar)
1278- return std::nullopt ;
1258+ // First check to see if we have a type for this wrapper variable, which will
1259+ // the case for e.g local wrappers in closures.
1260+ if (auto ty = cs.getTypeIfAvailable (wrapperVar))
1261+ return ty;
1262+
1263+ // If we don't have a type for the wrapper variable this shouldn't be a
1264+ // VarDecl we're solving for.
1265+ ASSERT (!cs.hasType (D) && " Should have recorded type for wrapper var" );
1266+
1267+ // For the backing property we need to query the request to ensure it kicks
1268+ // type-checking if necessary. Otherwise we can query the interface type.
1269+ auto ty = wrapperVar == D->getPropertyWrapperBackingProperty ()
1270+ ? D->getPropertyWrapperBackingPropertyType ()
1271+ : wrapperVar->getInterfaceType ();
1272+ if (!ty)
1273+ return Type ();
12791274
1280- return std::make_pair (projectionVar,
1281- projectionVar->getInterfaceType ());
1282- });
1275+ // If this is a for a property, substitute the base type. Otherwise we have
1276+ // a local property wrapper and need to map the resulting type into context.
1277+ if (auto baseType = resolvedOverload.choice .getBaseType ()) {
1278+ ty = baseType->getRValueType ()->getTypeOfMember (wrapperVar, ty);
1279+ } else {
1280+ ty = cs.DC ->mapTypeIntoContext (ty);
1281+ }
1282+ return ty;
12831283}
12841284
1285- std::optional<std::pair<VarDecl *, Type>>
1286- ConstraintSystem::getPropertyWrapperInformation (
1285+ Type ConstraintSystem::getPropertyWrapperProjectionType (
12871286 SelectedOverload resolvedOverload) {
1288- return getPropertyWrapperInformationFromOverload (
1289- resolvedOverload, DC,
1290- [](VarDecl *decl) -> std::optional<std::pair<VarDecl *, Type>> {
1291- if (!decl->hasAttachedPropertyWrapper ())
1292- return std::nullopt ;
1293-
1294- auto backingTy = decl->getPropertyWrapperBackingPropertyType ();
1295- if (!backingTy)
1296- return std::nullopt ;
1297-
1298- return std::make_pair (decl, backingTy);
1299- });
1287+ return getPropertyWrapperTypeFromOverload (
1288+ *this , resolvedOverload,
1289+ [&](VarDecl *decl) { return decl->getPropertyWrapperProjectionVar (); });
13001290}
13011291
1302- std::optional<std::pair<VarDecl *, Type>>
1303- ConstraintSystem::getWrappedPropertyInformation (
1292+ Type ConstraintSystem::getPropertyWrapperBackingType (
13041293 SelectedOverload resolvedOverload) {
1305- return getPropertyWrapperInformationFromOverload (
1306- resolvedOverload, DC,
1307- [](VarDecl *decl) -> std::optional<std::pair<VarDecl *, Type>> {
1308- if (auto wrapped = decl->getOriginalWrappedProperty ())
1309- return std::make_pair (decl, wrapped->getInterfaceType ());
1294+ return getPropertyWrapperTypeFromOverload (
1295+ *this , resolvedOverload,
1296+ [](VarDecl *decl) { return decl->getPropertyWrapperBackingProperty (); });
1297+ }
13101298
1311- return std::nullopt ;
1312- });
1299+ Type ConstraintSystem::getWrappedPropertyType (
1300+ SelectedOverload resolvedOverload) {
1301+ return getPropertyWrapperTypeFromOverload (
1302+ *this , resolvedOverload,
1303+ [](VarDecl *decl) { return decl->getOriginalWrappedProperty (); });
13131304}
13141305
13151306void ConstraintSystem::addOverloadSet (Type boundType,
0 commit comments