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
1343
1343
// / argument labels removed.
1344
1344
Type removeArgumentLabels (unsigned numArgumentLabels);
1345
1345
1346
+ // / Replace DynamicSelfType anywhere it appears in covariant position with
1347
+ // / its underlying Self type.
1348
+ Type eraseDynamicSelfType ();
1349
+
1346
1350
// / Replace DynamicSelfType anywhere it appears in covariant position with
1347
1351
// / the given type.
1348
1352
Type replaceDynamicSelfType (Type newSelfType);
Original file line number Diff line number Diff line change @@ -1342,19 +1342,34 @@ Type TypeBase::removeArgumentLabels(unsigned numArgumentLabels) {
1342
1342
return FunctionType::get (unlabeledParams, result, fnType->getExtInfo ());
1343
1343
}
1344
1344
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
+
1345
1360
Type TypeBase::replaceDynamicSelfType (Type newSelfType) {
1346
1361
if (!hasDynamicSelfType ())
1347
1362
return Type (this );
1348
1363
1349
1364
return Type (this ).transformWithPosition (
1350
1365
TypePosition::Covariant,
1351
1366
[&](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
+ });
1358
1373
}
1359
1374
1360
1375
Type TypeBase::withCovariantResultType () {
You can’t perform that action at this time.
0 commit comments