Skip to content

Commit 62f1303

Browse files
committed
[IDE] Fix assertion failure in PostfixCompletionCallback::Result::tryMerge
Unfortunately due to pre-checking multiple times the recorded application level can change. Just OR the bits together.
1 parent f49b760 commit 62f1303

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

lib/IDE/PostfixCompletion.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ bool PostfixCompletionCallback::Result::tryMerge(const Result &Other,
2727
if (BaseDecl != Other.BaseDecl)
2828
return false;
2929

30-
// These properties should match if we are talking about the same BaseDecl.
31-
assert(IsBaseDeclUnapplied == Other.IsBaseDeclUnapplied);
30+
// This should match if we are talking about the same BaseDecl.
3231
assert(BaseIsStaticMetaType == Other.BaseIsStaticMetaType);
3332

3433
auto baseTy = tryMergeBaseTypeForCompletionLookup(BaseTy, Other.BaseTy, DC);
@@ -56,6 +55,12 @@ bool PostfixCompletionCallback::Result::tryMerge(const Result &Other,
5655
ExpectsNonVoid &= Other.ExpectsNonVoid;
5756
IsImpliedResult |= Other.IsImpliedResult;
5857
IsInAsyncContext |= Other.IsInAsyncContext;
58+
59+
// Note this may differ if we pre-check multiple times since pre-checking
60+
// changes the recorded apply level.
61+
// FIXME: We ought to fix completion to not pre-check multiple times.
62+
IsBaseDeclUnapplied |= Other.IsBaseDeclUnapplied;
63+
5964
return true;
6065
}
6166

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"kind":"complete","signature":"swift::ide::PostfixCompletionCallback::Result::tryMerge(swift::ide::PostfixCompletionCallback::Result const&, swift::DeclContext*)"}
2-
// RUN: not --crash %target-swift-ide-test -code-completion --code-completion-token=COMPLETE -code-completion-diagnostics -source-filename %s
2+
// RUN: %target-swift-ide-test -code-completion --code-completion-token=COMPLETE -code-completion-diagnostics -source-filename %s
33
Int { switch { case Optional.some()#^COMPLETE^#

validation-test/IDE/issues_fixed/issue-75845.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,28 @@ struct Foo {
1515
// B: Begin completions
1616
// C: Decl[LocalVar]/Local: error[#any Error#]; name=error
1717
// D: Begin completions
18+
19+
enum E {
20+
case e(Error)
21+
22+
func foo() {
23+
var x = self
24+
do {
25+
} catch {
26+
x = .e(error)#^E^#
27+
// E: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: .foo()[#Void#]; name=foo()
28+
}
29+
}
30+
31+
static func bar() {
32+
do {
33+
} catch {
34+
_ = foo(.e(error))#^F^#
35+
// F: Decl[InstanceMethod]/CurrNominal/Flair[ArgLabels]: ()[#Void#]; name=()
36+
37+
_ = foo(.e(error))()#^G^#
38+
// G: Begin completions, 1 items
39+
// G: Keyword[self]/CurrNominal: .self[#Void#]; name=self
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)