Skip to content

[5.9][CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types #65934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,16 +724,16 @@ Type GenericSignatureImpl::getDependentUpperBounds(Type type) const {
argTypes.push_back(reducedType);
}

// We should have either constrained all primary associated types,
// or none of them.
if (!argTypes.empty()) {
if (argTypes.size() != primaryAssocTypes.size()) {
llvm::errs() << "Not all primary associated types constrained?\n";
llvm::errs() << "Interface type: " << type << "\n";
llvm::errs() << GenericSignature(this) << "\n";
abort();
}

// If we have constrained all primary associated types, create a
// parameterized protocol type. During code completion, we might call
// `getExistentialType` (which calls this method) on a generic parameter
// that doesn't have all parameters specified, e.g. to get a consise
// description of the parameter type to the following function.
//
// func foo<P: Publisher>(p: P) where P.Failure == Never
//
// In that case just add the base type in the default branch below.
if (argTypes.size() == primaryAssocTypes.size()) {
types.push_back(ParameterizedProtocolType::get(ctx, baseType, argTypes));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t

protocol Publisher<Output, Failure> {
associatedtype Output
associatedtype Failure
}

func foo<P: Publisher>(_ publisher: P) where P.Failure == Never

func test() {
foo(#^COMPLETE^#)
// Make sure we don’t crash
// COMPLETE: Begin completions
}