Resolve failing constraint for subscripts returning Self

This commit is contained in:
John Holdsworth
2019-04-17 17:14:16 +01:00
committed by Slava Pestov
parent c1c1801448
commit b799304fca

View File

@@ -1460,6 +1460,13 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
if (doesStorageProduceLValue(subscript, overload.getBaseType(), useDC))
elementTy = LValueType::get(elementTy);
else {
Type selfType = overload.getBaseType()->getRValueType()
->getMetatypeInstanceType()
->lookThroughAllOptionalTypes();
if (elementTy->hasDynamicSelfType())
elementTy = elementTy->replaceCovariantResultType(selfType, 0);
}
// See ConstraintSystem::resolveOverload() -- optional and dynamic
// subscripts are a special case, because the optionality is