@@ -72,6 +72,9 @@ class ResultBuilderTransform
72
72
DeclContext *dc;
73
73
ResultBuilder builder;
74
74
75
+ // / The source range of the body.
76
+ SourceRange bodyRange;
77
+
75
78
// / The result type of this result builder body.
76
79
Type ResultType;
77
80
@@ -80,9 +83,9 @@ class ResultBuilderTransform
80
83
81
84
public:
82
85
ResultBuilderTransform (ConstraintSystem &cs, DeclContext *dc,
83
- Type builderType, Type resultTy)
86
+ SourceRange bodyRange, Type builderType, Type resultTy)
84
87
: ctx(cs.getASTContext()), dc(dc), builder(cs, dc, builderType),
85
- ResultType (resultTy) {}
88
+ bodyRange (bodyRange), ResultType(resultTy) {}
86
89
87
90
UnsupportedElt getUnsupportedElement () const { return FirstUnsupported; }
88
91
@@ -238,12 +241,14 @@ class ResultBuilderTransform
238
241
// buildBlock higher.
239
242
buildBlockArguments.push_back (expr);
240
243
} else if (ctx.CompletionCallback && expr->getSourceRange ().isValid () &&
244
+ containsIDEInspectionTarget (bodyRange, ctx.SourceMgr ) &&
241
245
!containsIDEInspectionTarget (expr->getSourceRange (),
242
246
ctx.SourceMgr )) {
243
- // A statement that doesn't contain the code completion expression can't
244
- // influence the type of the code completion expression. Add a variable
245
- // for it that we can put into the buildBlock call but don't add the
246
- // expression itself into the transformed body to improve performance.
247
+ // A top-level expression that doesn't contain the code completion
248
+ // expression can't influence the type of the code completion expression
249
+ // if they're in the same result builder. Add a variable for it that we
250
+ // can put into the buildBlock call but don't add the expression itself
251
+ // into the transformed body to improve performance.
247
252
auto *resultVar = buildPlaceholderVar (expr->getStartLoc (), newBody);
248
253
buildBlockArguments.push_back (
249
254
builder.buildVarRef (resultVar, expr->getStartLoc ()));
@@ -1176,6 +1181,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
1176
1181
// let's do it and cache the result.
1177
1182
if (!transformedBody) {
1178
1183
ResultBuilderTransform transform (*this , fn.getAsDeclContext (),
1184
+ fn.getBody ()->getSourceRange (),
1179
1185
builderType, bodyResultType);
1180
1186
auto *body = transform.apply (fn.getBody ());
1181
1187
0 commit comments