mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user