File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -1337,16 +1337,11 @@ class alignas(1 << TypeAlignInBits) TypeBase
1337
1337
// / argument labels removed.
1338
1338
Type removeArgumentLabels (unsigned numArgumentLabels);
1339
1339
1340
- // / Replace the base type of the result type of the given function
1341
- // / type with a new result type, as per a DynamicSelf or other
1342
- // / covariant return transformation. The optionality of the
1343
- // / existing result will be preserved.
1344
- // /
1345
- // / \param newResultType The new result type.
1346
- // /
1347
- // / \param uncurryLevel The number of uncurry levels to apply before
1348
- // / replacing the type. With uncurry level == 0, this simply
1349
- // / replaces the current type with the new result type.
1340
+ // / Replace DynamicSelfType anywhere it appears in covariant position with
1341
+ // / the given type.
1342
+ Type replaceDynamicSelfType (Type newSelfType);
1343
+
1344
+ // / Deprecated in favor of the above.
1350
1345
Type replaceCovariantResultType (Type newResultType,
1351
1346
unsigned uncurryLevel);
1352
1347
Original file line number Diff line number Diff line change @@ -1329,6 +1329,21 @@ Type TypeBase::removeArgumentLabels(unsigned numArgumentLabels) {
1329
1329
return FunctionType::get (unlabeledParams, result, fnType->getExtInfo ());
1330
1330
}
1331
1331
1332
+ Type TypeBase::replaceDynamicSelfType (Type newSelfType) {
1333
+ if (!hasDynamicSelfType ())
1334
+ return Type (this );
1335
+
1336
+ return Type (this ).transformWithPosition (
1337
+ TypePosition::Covariant,
1338
+ [&](TypeBase *t, TypePosition pos) -> std::optional<Type> {
1339
+ if (isa<DynamicSelfType>(t) &&
1340
+ pos == TypePosition::Covariant) {
1341
+ return newSelfType;
1342
+ }
1343
+ return std::nullopt;
1344
+ });
1345
+ }
1346
+
1332
1347
Type TypeBase::replaceCovariantResultType (Type newResultType,
1333
1348
unsigned uncurryLevel) {
1334
1349
if (uncurryLevel == 0 ) {
You can’t perform that action at this time.
0 commit comments