Skip to content

Commit 861f5c8

Browse files
committed
[CSClosure] Conjunctions should reference result builder type variables
If builder type is not fully resolved, conjunction should reference its variables otherwise it would get disconnected from required contextual constraints.
1 parent 22ab6ec commit 861f5c8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ static void createConjunction(ConstraintSystem &cs,
254254
// reference a type variable representing closure type,
255255
// otherwise it would get disconnected from its contextual type.
256256
referencedVars.push_back(cs.getType(closure)->castTo<TypeVariableType>());
257+
258+
// Result builder could be generic but attribute allows its use
259+
// in "unbound" form (i.e. `@Builder` where `Builder` is defined
260+
// as `struct Builder<T>`). Generic parameters of such a result
261+
// builder type are inferable from context, namely from `build*`
262+
// calls injected by the transform, and are not always resolved at
263+
// the time conjunction is created.
264+
//
265+
// Conjunction needs to reference all the type variables associated
266+
// with result builder just like parameters and result type of
267+
// the closure in order to stay connected to its context.
268+
if (auto builder = cs.getAppliedResultBuilderTransform(closure)) {
269+
SmallPtrSet<TypeVariableType *, 4> builderVars;
270+
builder->builderType->getTypeVariables(builderVars);
271+
referencedVars.append(builderVars.begin(), builderVars.end());
272+
}
273+
257274
// Body of the closure is always isolated from its context, only
258275
// its individual elements are allowed access to type information
259276
// from the outside e.g. parameters/result type.

0 commit comments

Comments
 (0)