Skip to content

Commit 5eb893f

Browse files
[Sema] Make isRawRepresentableGenericFunction to make sure is the stdlib fn and the requirement are exact
1 parent c43ca8a commit 5eb893f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,15 +3840,20 @@ static bool isRawRepresentableGenericFunction(
38403840
ASTContext &ctx, const ValueDecl *witness,
38413841
const NormalProtocolConformance *conformance) {
38423842
auto *fnDecl = dyn_cast<AbstractFunctionDecl>(witness);
3843-
return fnDecl && fnDecl->isGeneric() &&
3843+
if (!fnDecl || !fnDecl->isStdlibDecl())
3844+
return false;
3845+
3846+
return fnDecl->isGeneric() && fnDecl->getGenericParams()->size() == 1 &&
3847+
fnDecl->getGenericRequirements().size() == 2 &&
38443848
llvm::all_of(
38453849
fnDecl->getGenericRequirements(), [&](Requirement genericReq) {
3846-
return genericReq.getKind() == RequirementKind::Conformance &&
3847-
(genericReq.getProtocolDecl() ==
3848-
ctx.getProtocol(
3849-
KnownProtocolKind::RawRepresentable) ||
3850-
genericReq.getProtocolDecl() ==
3851-
conformance->getProtocol());
3850+
if (genericReq.getKind() != RequirementKind::Conformance)
3851+
return false;
3852+
return genericReq.getProtocolDecl() ==
3853+
ctx.getProtocol(
3854+
KnownProtocolKind::RawRepresentable) ||
3855+
genericReq.getProtocolDecl() ==
3856+
conformance->getProtocol();
38523857
});
38533858
}
38543859

0 commit comments

Comments
 (0)