Files
swift-mirror/test/SourceKit/CodeComplete/complete_sequence_builderfunc.swift
Rintaro Ishizaki e953e523a0 [CodeCompletion] Fast completion inside function builder function
`PreCheckFunctionBuilderRequest` applies `PreCheckExpression` to the
expressions inside the function body. Previously it used to receive only
`AnyFunctionRef` (`FunctionDecl` or `ClosureExpr`) as the parameter.
However, when fast-completion kicks-in, it replaces the body of the
function, then tries to call `PreCheckFunctionBuilderRequest` again, with
the same function decl as before. It used to return cached "Success"
result, but it didn't actually apply `PreCheckExpression`. So any
`UnresolvedDeclRefExpr` remained unresolved.

In this patch, make `PreCheckFunctionBuilderRequest` receive "body" of the
function as well, so it doesn't return the cached result for the *previous*
body.

rdar://problem/65692922
2020-07-16 23:38:49 -07:00

52 lines
1.1 KiB
Swift

protocol Entity {}
struct Empty: Entity {
var value: Void = ()
}
@_functionBuilder
struct Builder {
static func buildBlock() -> { Empty() }
static func buildBlock<T: Entity>(_ t: T) -> T { t }
}
struct MyValue {
var id: Int
var title: String
}
func build(_ arg: (MyValue) -> String) -> Empty { Empty() }
struct MyStruct {
@Builder var body: some Entity {
build { value in
value./*HERE * 2*/
} /*HERE*/
}
}
// RUN: %sourcekitd-test \
// RUN: -req=complete -pos=22:13 %s -- %s == \
// RUN: -req=complete -pos=22:13 %s -- %s == \
// RUN: -req=complete -pos=23:7 %s -- %s \
// RUN: | tee %t.result | %FileCheck %s
// CHECK-LABEL: key.results: [
// CHECK-DAG: key.description: "id"
// CHECK-DAG: key.description: "title"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK-NOT: key.reusingastcontext: 1
// CHECK-LABEL: key.results: [
// CHECK-DAG: key.description: "id"
// CHECK-DAG: key.description: "title"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK: key.reusingastcontext: 1
// CHECK-LABEL: key.results: [
// CHECK-DAG: key.description: "value"
// CHECK: ]
// CHECK: key.reusingastcontext: 1