@@ -488,7 +488,7 @@ static Type getResultType(TypeChecker &TC, FuncDecl *fn, Type resultType) {
488
488
489
489
// / Determine whether the given type is \c Self, an associated type of \c Self,
490
490
// / or a concrete type.
491
- static bool isSelfDerivedOrConcrete (Type type) {
491
+ static bool isSelfDerivedOrConcrete (Type protoSelf, Type type) {
492
492
// Check for a concrete type.
493
493
if (!type->hasTypeParameter ())
494
494
return true ;
@@ -498,8 +498,8 @@ static bool isSelfDerivedOrConcrete(Type type) {
498
498
type = depMem->getBase ();
499
499
}
500
500
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) ;
503
503
504
504
return false ;
505
505
}
@@ -544,11 +544,12 @@ TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
544
544
if (!invalid && func->getGenericParams () &&
545
545
isa<ProtocolDecl>(func->getDeclContext ())) {
546
546
auto proto = cast<ProtocolDecl>(func->getDeclContext ());
547
+ auto protoSelf = proto->getSelfInterfaceType ();
547
548
for (auto req : sig->getRequirements ()) {
548
549
// If one of the types in the requirement is dependent on a non-Self
549
550
// 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 ()))
552
553
continue ;
553
554
554
555
// The conformance of 'Self' to the protocol is okay.
0 commit comments