File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -1343,6 +1343,10 @@ class alignas(1 << TypeAlignInBits) TypeBase
13431343 // / argument labels removed.
13441344 Type removeArgumentLabels (unsigned numArgumentLabels);
13451345
1346+ // / Replace DynamicSelfType anywhere it appears in covariant position with
1347+ // / its underlying Self type.
1348+ Type eraseDynamicSelfType ();
1349+
13461350 // / Replace DynamicSelfType anywhere it appears in covariant position with
13471351 // / the given type.
13481352 Type replaceDynamicSelfType (Type newSelfType);
Original file line number Diff line number Diff line change @@ -1342,19 +1342,34 @@ Type TypeBase::removeArgumentLabels(unsigned numArgumentLabels) {
13421342 return FunctionType::get (unlabeledParams, result, fnType->getExtInfo ());
13431343}
13441344
1345+ Type TypeBase::eraseDynamicSelfType () {
1346+ if (!hasDynamicSelfType ())
1347+ return Type (this );
1348+
1349+ return Type (this ).transformWithPosition (
1350+ TypePosition::Covariant,
1351+ [&](TypeBase *t, TypePosition pos) -> std::optional<Type> {
1352+ if (isa<DynamicSelfType>(t) &&
1353+ pos == TypePosition::Covariant) {
1354+ return cast<DynamicSelfType>(t)->getSelfType ();
1355+ }
1356+ return std::nullopt ;
1357+ });
1358+ }
1359+
13451360Type TypeBase::replaceDynamicSelfType (Type newSelfType) {
13461361 if (!hasDynamicSelfType ())
13471362 return Type (this );
13481363
13491364 return Type (this ).transformWithPosition (
13501365 TypePosition::Covariant,
13511366 [&](TypeBase *t, TypePosition pos) -> std::optional<Type> {
1352- if (isa<DynamicSelfType>(t) &&
1353- pos == TypePosition::Covariant) {
1354- return newSelfType;
1355- }
1356- return std::nullopt ;
1357- });
1367+ if (isa<DynamicSelfType>(t) &&
1368+ pos == TypePosition::Covariant) {
1369+ return newSelfType;
1370+ }
1371+ return std::nullopt ;
1372+ });
13581373}
13591374
13601375Type TypeBase::withCovariantResultType () {
You can’t perform that action at this time.
0 commit comments