Skip to content

Commit 7a390e1

Browse files
committed
[code-completion] Improve robustness of Solution::computeSubstitutions and check if OpenedTypes contains the provided locator.
Fixes validation-test/IDE/crashers/103-swift-constraints-solution-resolvelocatortodecl.swift.
1 parent 5b82297 commit 7a390e1

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,19 @@ Type Solution::computeSubstitutions(
8585
SmallVectorImpl<Substitution> &result) const {
8686
auto &tc = getConstraintSystem().getTypeChecker();
8787

88+
// Produce the concrete form of the opened type.
89+
Type type = simplifyType(tc, openedType);
90+
8891
// Gather the substitutions from dependent types to concrete types.
8992
auto openedTypes = OpenedTypes.find(locator);
90-
assert(openedTypes != OpenedTypes.end() && "Missing opened type information");
93+
if (openedTypes == OpenedTypes.end())
94+
return type;
9195
TypeSubstitutionMap subs;
9296
for (const auto &opened : openedTypes->second) {
9397
subs[opened.first->castTo<GenericTypeParamType>()] =
9498
getFixedType(opened.second);
9599
}
96100

97-
// Produce the concrete form of the opened type.
98-
Type type = simplifyType(tc, openedType);
99-
100101
auto mod = getConstraintSystem().DC->getParentModule();
101102
GenericSignature *sig;
102103
if (auto genericFn = origType->getAs<GenericFunctionType>()) {

validation-test/IDE/crashers/103-swift-constraints-solution-resolvelocatortodecl.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
protocol b
3+
func b{b#^A^#

0 commit comments

Comments
 (0)