Skip to content

Commit 7260c3b

Browse files
authored
Merge pull request #65818 from ahoppen/ahoppen/stress-tester-fixes
[CodeCompletion] Fix two crashers found by the stress tester
2 parents 0f25f02 + 5024955 commit 7260c3b

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ class ConstraintSystem {
29252925
/// Whether the argument \p Arg occurs after the code completion token and
29262926
/// thus should be ignored and not generate any fixes.
29272927
bool isArgumentIgnoredForCodeCompletion(Expr *Arg) const {
2928-
return IgnoredArguments.count(Arg) > 0;
2928+
return IgnoredArguments.count(Arg) > 0 && isForCodeCompletion();
29292929
}
29302930

29312931
/// Whether the constraint system has ignored any arguments for code

lib/IDE/ArgumentCompletion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ bool ArgumentTypeCheckCompletionCallback::addPossibleParams(
5353
// Since not all function types are backed by declarations (e.g. closure
5454
// paramters), `DeclParam` might be `nullptr`.
5555
const AnyFunctionType::Param *TypeParam = &ParamsToPass[Idx];
56-
const ParamDecl *DeclParam = getParameterAt(Res.FuncDeclRef, Idx);
56+
const ParamDecl *DeclParam = nullptr;
57+
if (Res.FuncDeclRef) {
58+
DeclParam = getParameterAt(Res.FuncDeclRef, Idx);
59+
}
5760

5861
bool Required = true;
5962
if (DeclParam && DeclParam->isDefaultArgument()) {

test/IDE/complete_call_pattern_heuristics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ func testArg2Name3() {
3434
// LABELED_FIRSTARG-DAG: Pattern/Local/Flair[ArgLabels]: {#arg1: Int#}[#Int#];
3535
// LABELED_FIRSTARG-NOT: ['(']{#arg1: Int#}, {#arg2: Int#}[')'][#Void#];
3636

37+
func subscriptAccess(info: [String: Int]) {
38+
info[#^SUBSCRIPT_ACCESS^#]
39+
// SUBSCRIPT_ACCESS: Pattern/Local/Flair[ArgLabels]: {#keyPath: KeyPath<[String : Int], Value>#}[#KeyPath<[String : Int], Value>#]; name=keyPath:
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
func overloaded(content: () -> Int) {}
5+
func overloaded(@MyResultBuilder stuff: () -> Int) {}
6+
7+
@resultBuilder struct MyResultBuilder {
8+
static func buildExpression(_ content: Int) -> Int { content }
9+
static func buildBlock() -> Int { 4 }
10+
}
11+
12+
struct HStack {
13+
init(spacing: Double, @MyResultBuilder content: () -> Int) {}
14+
func qadding(_ length: Double) { }
15+
}
16+
17+
func test() {
18+
overloaded {
19+
HStack(spacing: #^COMPLETE^#) {}
20+
.qadding(32)
21+
}
22+
}
23+
24+
// COMPLETE: Literal[Integer]/None/TypeRelation[Convertible]: 0[#Double#]; name=0

0 commit comments

Comments
 (0)