Skip to content

Commit c301176

Browse files
committed
[ConstraintSystem] Allow SolutionApplicationTarget to store the
innermost call to init(wrappedValue:) if the target is for initialization of a property wrapper's backing storage.
1 parent d22b984 commit c301176

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,6 +4157,7 @@ SolutionApplicationTarget::SolutionApplicationTarget(
41574157
expression.convertType = convertType;
41584158
expression.pattern = nullptr;
41594159
expression.wrappedVar = nullptr;
4160+
expression.innermostWrappedValueInit = nullptr;
41604161
expression.isDiscarded = isDiscarded;
41614162
expression.bindPatternVarsOneWay = false;
41624163
expression.patternBinding = nullptr;

lib/Sema/ConstraintSystem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,10 @@ class SolutionApplicationTarget {
12021202
/// this is an initialization involving a property wrapper.
12031203
VarDecl *wrappedVar;
12041204

1205+
/// The innermost call to \c init(wrappedValue:), if this is an
1206+
/// initialization involving a property wrapper.
1207+
ApplyExpr *innermostWrappedValueInit;
1208+
12051209
/// Whether the expression result will be discarded at the end.
12061210
bool isDiscarded;
12071211

@@ -1384,6 +1388,20 @@ class SolutionApplicationTarget {
13841388
expression.bindPatternVarsOneWay;
13851389
}
13861390

1391+
/// Whether or not an opaque value placeholder should be injected into the
1392+
/// first \c wrappedValue argument of an apply expression.
1393+
bool shouldInjectWrappedValuePlaceholder(ApplyExpr *apply) const {
1394+
if (kind != Kind::expression ||
1395+
expression.contextualPurpose != CTP_Initialization)
1396+
return false;
1397+
1398+
auto *wrappedVar = expression.wrappedVar;
1399+
if (!wrappedVar || wrappedVar->isStatic())
1400+
return false;
1401+
1402+
return expression.innermostWrappedValueInit == apply;
1403+
}
1404+
13871405
/// Retrieve the wrapped variable when initializing a pattern with a
13881406
/// property wrapper.
13891407
VarDecl *getInitializationWrappedVar() const {

0 commit comments

Comments
 (0)