Skip to content

Commit 99f914f

Browse files
ahoppenxedin
andcommitted
[CodeCompletion] Fix a crash when completing the call pattern of a function that takes a parameter pack
The issue here was that we inferred the contextual type of the `Mixer` call to be the following, inferred from the result type of the partial call to the initializer of `Mixer` ``` (bound_generic_struct_type decl="swift_ide_test.(file).Mixer@/Users/alex/src/swift/test/IDE/complete_parameter_pack_as_call_argument.swift:3:8" (pack_type num_elements=1 (pack_expansion_type (pattern=unresolved_type) (count=unresolved_type)))) ``` Technically, the contextual type that we should have here should be `Any` (from `print`) but getting that information out of the constraint system turns out to be quite hard. #72568 makes some improvements in this area but in general the constraint system does not contain enough information to figure out the contextual type of an arbitrary expression. The important thing right now is that the unresolved type in here trips the constraint system over when comparing types of code completion results with the contextual type. To prevent the crash for now, reset the expected call type if the computed type contains an unresolved type. rdar://124166587 Co-authored-by: Pavel Yaskevich <[email protected]>
1 parent 9c60fc2 commit 99f914f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ Solution::computeSubstitutions(NullablePtr<ValueDecl> decl,
9898
TypeSubstitutionMap subs;
9999
for (const auto &opened : openedTypes->second) {
100100
auto type = getFixedType(opened.second);
101-
if (opened.first->isParameterPack() && !type->is<PackType>())
102-
type = PackType::getSingletonPackExpansion(type);
101+
if (opened.first->isParameterPack()) {
102+
if (type->is<PlaceholderType>()) {
103+
auto &ctx = type->getASTContext();
104+
type =
105+
PackType::get(ctx, {PackExpansionType::get(ctx.TheUnresolvedType,
106+
ctx.TheUnresolvedType)});
107+
} else if (!type->is<PackType>())
108+
type = PackType::getSingletonPackExpansion(type);
109+
}
103110
subs[opened.first] = type;
104111
}
105112

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %batch-code-completion
2+
3+
struct Mixer<each Source: Signal>: Signal {}
4+
5+
print(Mixer(#^COMPLETE^#))
6+
7+
// COMPLETE: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['('][')'][#Mixer<repeat each Source>#];

0 commit comments

Comments
 (0)