@@ -2502,30 +2502,26 @@ static VarDecl *synthesizePropertyWrapperProjectionVar(
2502
2502
return property;
2503
2503
}
2504
2504
2505
- static void typeCheckSynthesizedWrapperInitializer (
2506
- PatternBindingDecl *pbd, VarDecl *backingVar, PatternBindingDecl *parentPBD,
2507
- Expr *&initializer) {
2505
+ static void typeCheckSynthesizedWrapperInitializer (VarDecl *wrappedVar,
2506
+ Expr *&initializer) {
2508
2507
// Figure out the context in which the initializer was written.
2508
+ auto *parentPBD = wrappedVar->getParentPatternBinding ();
2509
+ auto i = parentPBD->getPatternEntryIndexForVarDecl (wrappedVar);
2509
2510
DeclContext *originalDC = parentPBD->getDeclContext ();
2510
2511
if (!originalDC->isLocalContext ()) {
2511
2512
auto initContext =
2512
- cast_or_null<PatternBindingInitializer>(parentPBD->getInitContext (0 ));
2513
+ cast_or_null<PatternBindingInitializer>(parentPBD->getInitContext (i ));
2513
2514
if (initContext)
2514
2515
originalDC = initContext;
2515
2516
}
2516
2517
2517
2518
// Type-check the initialization.
2518
- {
2519
- auto *wrappedVar = backingVar->getOriginalWrappedProperty ();
2520
- auto i = parentPBD->getPatternEntryIndexForVarDecl (wrappedVar);
2521
- auto *pattern = parentPBD->getPattern (i);
2522
- TypeChecker::typeCheckBinding (pattern, initializer, originalDC,
2523
- wrappedVar->getType (), parentPBD, i);
2524
- }
2519
+ auto *pattern = parentPBD->getPattern (i);
2520
+ TypeChecker::typeCheckBinding (pattern, initializer, originalDC,
2521
+ wrappedVar->getType (), parentPBD, i);
2525
2522
2526
- const auto i = pbd->getPatternEntryIndexForVarDecl (backingVar);
2527
2523
if (auto initializerContext =
2528
- dyn_cast_or_null<Initializer>(pbd ->getInitContext (i))) {
2524
+ dyn_cast_or_null<Initializer>(parentPBD ->getInitContext (i))) {
2529
2525
TypeChecker::contextualizeInitializer (initializerContext, initializer);
2530
2526
}
2531
2527
}
@@ -2807,8 +2803,7 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
2807
2803
// FIXME: Record this expression somewhere so that DI can perform the
2808
2804
// initialization itself.
2809
2805
Expr *initializer = nullptr ;
2810
- typeCheckSynthesizedWrapperInitializer (pbd, backingVar, parentPBD,
2811
- initializer);
2806
+ typeCheckSynthesizedWrapperInitializer (var, initializer);
2812
2807
pbd->setInit (0 , initializer);
2813
2808
pbd->setInitializerChecked (0 );
2814
2809
} else if (var->hasObservers () && !dc->isTypeContext ()) {
@@ -2846,28 +2841,20 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
2846
2841
}
2847
2842
}
2848
2843
2849
- // If no initial wrapped value was provided via '=' and either:
2850
- // 1. Not all of the attached property wrappers have init(wrappedValue:), or
2851
- // 2. An initializer has already been synthesized from arguments in the
2852
- // property wrapper attribute,
2853
- // then this property wrapper cannot be initialized out-of-line with a wrapped
2854
- // value.
2855
- if (!wrappedValue && (!var->allAttachedPropertyWrappersHaveWrappedValueInit () ||
2856
- initializer)) {
2857
- return PropertyWrapperBackingPropertyInfo (backingVar, projectionVar, nullptr ,
2858
- projectedValueInit);
2859
- }
2860
-
2861
2844
// Form the initialization of the backing property from a value of the
2862
2845
// original property's type.
2863
- Expr *wrappedValueInit = initializer;
2864
- if (!wrappedValueInit) {
2846
+ Expr *wrappedValueInit = nullptr ;
2847
+ if (wrappedValue) {
2848
+ wrappedValueInit = initializer;
2849
+ } else if (!initializer &&
2850
+ var->allAttachedPropertyWrappersHaveWrappedValueInit ()) {
2865
2851
wrappedValueInit = PropertyWrapperValuePlaceholderExpr::create (
2866
2852
ctx, var->getSourceRange (), var->getType (), /* wrappedValue=*/ nullptr );
2867
2853
2868
2854
if (auto *param = dyn_cast<ParamDecl>(var)) {
2869
- wrappedValueInit = buildPropertyWrapperInitCall (var, backingVar->getType (), wrappedValueInit,
2870
- PropertyWrapperInitKind::WrappedValue);
2855
+ wrappedValueInit = buildPropertyWrapperInitCall (
2856
+ var, backingVar->getType (), wrappedValueInit,
2857
+ PropertyWrapperInitKind::WrappedValue);
2871
2858
TypeChecker::typeCheckExpression (wrappedValueInit, dc);
2872
2859
2873
2860
// Check initializer effects.
@@ -2877,8 +2864,7 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
2877
2864
checkInitializerActorIsolation (initContext, wrappedValueInit);
2878
2865
TypeChecker::checkInitializerEffects (initContext, wrappedValueInit);
2879
2866
} else {
2880
- typeCheckSynthesizedWrapperInitializer (
2881
- pbd, backingVar, var->getParentPatternBinding (), wrappedValueInit);
2867
+ typeCheckSynthesizedWrapperInitializer (var, wrappedValueInit);
2882
2868
}
2883
2869
}
2884
2870
0 commit comments