@@ -3963,6 +3963,17 @@ void ConformanceChecker::resolveSingleTypeWitness(
3963
3963
}
3964
3964
}
3965
3965
3966
+ // Not all protocol members are requirements.
3967
+ static bool isRequirement (ValueDecl *requirement) {
3968
+ if (auto *FD = dyn_cast<FuncDecl>(requirement))
3969
+ if (FD->isAccessor ())
3970
+ return false ;
3971
+ if (isa<TypeAliasDecl>(requirement) ||
3972
+ isa<NominalTypeDecl>(requirement))
3973
+ return false ;
3974
+ return true ;
3975
+ }
3976
+
3966
3977
void ConformanceChecker::resolveSingleWitness (ValueDecl *requirement) {
3967
3978
assert (!isa<AssociatedTypeDecl>(requirement) && " Not a value witness" );
3968
3979
assert (!Conformance->hasWitness (requirement) && " Already resolved" );
@@ -3982,12 +3993,7 @@ void ConformanceChecker::resolveSingleWitness(ValueDecl *requirement) {
3982
3993
return ;
3983
3994
}
3984
3995
3985
- // If this is a getter/setter for a funcdecl, ignore it.
3986
- if (auto *FD = dyn_cast<FuncDecl>(requirement))
3987
- if (FD->isAccessor ())
3988
- return ;
3989
- // If this is a typealias, it does not need a witness check.
3990
- if (isa<TypeAliasDecl>(requirement))
3996
+ if (!isRequirement (requirement))
3991
3997
return ;
3992
3998
3993
3999
// Resolve all associated types before trying to resolve this witness.
@@ -4132,15 +4138,11 @@ void ConformanceChecker::checkConformance() {
4132
4138
continue ;
4133
4139
4134
4140
// Associated type requirements handled above.
4135
- if (isa<AssociatedTypeDecl >(requirement))
4141
+ if (isa<TypeDecl >(requirement))
4136
4142
continue ;
4137
4143
4138
4144
// Type aliases don't have requirements themselves.
4139
- if (isa<TypeAliasDecl>(requirement))
4140
- continue ;
4141
-
4142
- // Nominal types nested inside protocols are not requirements.
4143
- if (isa<NominalTypeDecl>(requirement))
4145
+ if (!isRequirement (requirement))
4144
4146
continue ;
4145
4147
4146
4148
// / Local function to finalize the witness.
@@ -5468,14 +5470,20 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
5468
5470
DefaultWitnessChecker checker (*this , proto);
5469
5471
5470
5472
for (auto *requirement : proto->getMembers ()) {
5471
- if (isa<AssociatedTypeDecl>(requirement ))
5473
+ if (requirement-> isInvalid ( ))
5472
5474
continue ;
5473
5475
5474
- if (requirement->isInvalid ())
5476
+ auto *valueDecl = dyn_cast<ValueDecl>(requirement);
5477
+ if (!valueDecl)
5478
+ continue ;
5479
+
5480
+ if (isa<TypeDecl>(valueDecl))
5481
+ continue ;
5482
+
5483
+ if (!isRequirement (valueDecl))
5475
5484
continue ;
5476
5485
5477
- if (auto *valueDecl = dyn_cast<ValueDecl>(requirement))
5478
- checker.resolveWitnessViaLookup (valueDecl);
5486
+ checker.resolveWitnessViaLookup (valueDecl);
5479
5487
}
5480
5488
}
5481
5489
0 commit comments