Skip to content

Commit 1930a8a

Browse files
committed
Sema: Use getSelfInterfaceType() instead of checking for depth 0/index 0
1 parent 67328f6 commit 1930a8a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ static Type getResultType(TypeChecker &TC, FuncDecl *fn, Type resultType) {
488488

489489
/// Determine whether the given type is \c Self, an associated type of \c Self,
490490
/// or a concrete type.
491-
static bool isSelfDerivedOrConcrete(Type type) {
491+
static bool isSelfDerivedOrConcrete(Type protoSelf, Type type) {
492492
// Check for a concrete type.
493493
if (!type->hasTypeParameter())
494494
return true;
@@ -498,8 +498,8 @@ static bool isSelfDerivedOrConcrete(Type type) {
498498
type = depMem->getBase();
499499
}
500500

501-
if (auto gp = type->getAs<GenericTypeParamType>())
502-
return gp->getDepth() == 0 && gp->getIndex() == 0;
501+
if (type->is<GenericTypeParamType>())
502+
return type->isEqual(protoSelf);
503503

504504
return false;
505505
}
@@ -544,11 +544,12 @@ TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
544544
if (!invalid && func->getGenericParams() &&
545545
isa<ProtocolDecl>(func->getDeclContext())) {
546546
auto proto = cast<ProtocolDecl>(func->getDeclContext());
547+
auto protoSelf = proto->getSelfInterfaceType();
547548
for (auto req : sig->getRequirements()) {
548549
// If one of the types in the requirement is dependent on a non-Self
549550
// type parameter, this requirement is okay.
550-
if (!isSelfDerivedOrConcrete(req.getFirstType()) ||
551-
!isSelfDerivedOrConcrete(req.getSecondType()))
551+
if (!isSelfDerivedOrConcrete(protoSelf, req.getFirstType()) ||
552+
!isSelfDerivedOrConcrete(protoSelf, req.getSecondType()))
552553
continue;
553554

554555
// The conformance of 'Self' to the protocol is okay.

0 commit comments

Comments
 (0)