[CS] Fix crasher caught by stress tester

We need to be more lenient checking here as the
type variable may not be bound yet.
This commit is contained in:
Hamish Knight
2021-10-12 09:51:45 +01:00
parent b8e4c676c6
commit ac50dfd1d4
2 changed files with 21 additions and 8 deletions

View File

@@ -771,16 +771,18 @@ static void addKeyPathDynamicMemberOverloads(
/// shouldn't be compared.
static Optional<std::pair<Type, Type>>
getConstructorParamsAsTuples(ASTContext &ctx, Type boundTy1, Type boundTy2) {
// If the bound types are placeholders, they haven't been resolved, so let's
// not try and rank them.
if (boundTy1->isPlaceholder() || boundTy2->isPlaceholder())
auto choiceTy1 =
boundTy1->lookThroughAllOptionalTypes()->getAs<FunctionType>();
auto choiceTy2 =
boundTy2->lookThroughAllOptionalTypes()->getAs<FunctionType>();
// If the type variables haven't been bound to functions yet, let's not try
// and rank them.
if (!choiceTy1 || !choiceTy2)
return None;
auto choiceTy1 = boundTy1->lookThroughAllOptionalTypes();
auto choiceTy2 = boundTy2->lookThroughAllOptionalTypes();
auto initParams1 = choiceTy1->castTo<FunctionType>()->getParams();
auto initParams2 = choiceTy2->castTo<FunctionType>()->getParams();
auto initParams1 = choiceTy1->getParams();
auto initParams2 = choiceTy2->getParams();
if (initParams1.size() != initParams2.size())
return None;

View File

@@ -0,0 +1,11 @@
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=CC
// PR #39543: Make sure we can complete in this position without crashing.
extension String {
init(format: String, _: Any) { fatalError() }
}
extension RandomAccessCollection {
func foo() {
print(String(format: "", Int(distance(from:#^CC^# startIndex, to: startIndex))))
}
}