From dfb521230c76c121d66c111210ac5a879c79d097 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 7 Jul 2020 13:26:18 -0700 Subject: [PATCH] [Index] Fast path for getting value member Avoid solving constraint system if there's only one viable overload. This should also avoids a crash we are seeing in 'candidates.size() == 1' branch in the constraint system. rdar://problem/64636688 (cherry picked from commit 026904990c3553fb38123c8281fa27a80449d6ee) --- lib/Sema/CSGen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index a1b6f903cc8b1..a913ddafec0dc 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -4693,6 +4693,13 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) { if (LookupResult.ViableCandidates.empty()) return Result; + // If there's only one viable member, that is the best one. + if (LookupResult.ViableCandidates.size() == 1) { + Result.Impl->BestIdx = Result.Impl->AllDecls.size(); + Result.Impl->AllDecls.push_back(LookupResult.ViableCandidates[0].getDecl()); + return Result; + } + // Try to figure out the best overload. ConstraintLocator *Locator = CS.getConstraintLocator(nullptr); TypeVariableType *TV = CS.createTypeVariable(Locator,