AST: Add ASTContext::TheSelfType for convenience

This commit is contained in:
Slava Pestov
2025-04-25 13:32:04 -04:00
parent 5d36643af4
commit cf1572c65b
13 changed files with 24 additions and 37 deletions

View File

@@ -98,7 +98,7 @@ RequirementEnvironment::RequirementEnvironment(
// type.
if (type->isEqual(selfType)) {
if (covariantSelf)
return GenericTypeParamType::getType(/*depth=*/0, /*index=*/0, ctx);
return ctx.TheSelfType;
return substConcreteType;
}
// Other requirement generic parameters map 1:1 with their depth
@@ -173,8 +173,7 @@ RequirementEnvironment::RequirementEnvironment(
// If the conforming type is a class, add a class-constrained 'Self'
// parameter.
if (covariantSelf) {
auto paramTy = GenericTypeParamType::getType(/*depth=*/0, /*index=*/0, ctx);
genericParamTypes.push_back(paramTy);
genericParamTypes.push_back(ctx.TheSelfType);
}
// Now, add all generic parameters from the conforming type.
@@ -188,8 +187,7 @@ RequirementEnvironment::RequirementEnvironment(
// Next, add requirements.
SmallVector<Requirement, 2> requirements;
if (covariantSelf) {
auto paramTy = GenericTypeParamType::getType(/*depth=*/0, /*index=*/0, ctx);
Requirement reqt(RequirementKind::Superclass, paramTy, substConcreteType);
Requirement reqt(RequirementKind::Superclass, ctx.TheSelfType, substConcreteType);
requirements.push_back(reqt);
}