Skip to content

Commit ff7e11c

Browse files
committed
[CodeComplete] Fix crash when completing in a string literal in a result builder
1 parent 395df14 commit ff7e11c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/IDE/PostfixCompletion.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ getClosureActorIsolation(const Solution &S, AbstractClosureExpr *ACE) {
5858
return Ty;
5959
}
6060
}
61+
if (!S.hasType(E)) {
62+
return Type();
63+
}
6164
return getTypeForCompletion(S, E);
6265
};
6366
auto getClosureActorIsolationThunk = [&S](AbstractClosureExpr *ACE) {

test/IDE/complete_in_result_builder.swift

+27
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,30 @@ func testCompleteGlobalInResultBuilderIf() {
302302
// GLOBAL_IN_RESULT_BUILDER_IF-DAG: Decl[Struct]/Local/TypeRelation[Convertible]: MyView[#MyView#]; name=MyView
303303
// GLOBAL_IN_RESULT_BUILDER_IF: End completions
304304
}
305+
306+
func testInStringLiteralInResultBuilder() {
307+
func buildResult<Content>(@MyResultBuilder content: () -> Content) {}
308+
309+
@resultBuilder
310+
struct MyResultBuilder {
311+
static func buildBlock(_ components: String) -> String {
312+
components
313+
}
314+
}
315+
316+
struct Foo {
317+
var bar: Int
318+
}
319+
320+
func withClosure(_ x: () -> Bool) -> String { return "" }
321+
322+
func test(foo: Foo) {
323+
buildResult {
324+
"\(withClosure { foo.#^IN_STRING_LITERAL_IN_RESULT_BUILDER^# })"
325+
}
326+
}
327+
// IN_STRING_LITERAL_IN_RESULT_BUILDER: Begin completions, 2 items
328+
// IN_STRING_LITERAL_IN_RESULT_BUILDER-DAG: Keyword[self]/CurrNominal: self[#Foo#]; name=self
329+
// IN_STRING_LITERAL_IN_RESULT_BUILDER-DAG: Decl[InstanceVar]/CurrNominal: bar[#Int#]; name=bar
330+
// IN_STRING_LITERAL_IN_RESULT_BUILDER: End completions
331+
}

0 commit comments

Comments
 (0)