mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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;
|
||||
|
||||
|
||||
11
test/Constraints/pr39543.swift
Normal file
11
test/Constraints/pr39543.swift
Normal 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))))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user