@@ -101,7 +101,8 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
101
101
// / type.
102
102
static ConstructorDecl *
103
103
findSuitableWrapperInit (ASTContext &ctx, NominalTypeDecl *nominal,
104
- VarDecl *valueVar, PropertyWrapperInitKind initKind) {
104
+ VarDecl *valueVar, PropertyWrapperInitKind initKind,
105
+ const SmallVectorImpl<ValueDecl *> &decls) {
105
106
enum class NonViableReason {
106
107
Failable,
107
108
ParameterTypeMismatch,
@@ -111,7 +112,6 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
111
112
SmallVector<std::tuple<ConstructorDecl *, NonViableReason, Type>, 2 >
112
113
nonviable;
113
114
SmallVector<ConstructorDecl *, 2 > viableInitializers;
114
- SmallVector<ValueDecl *, 2 > decls;
115
115
116
116
Identifier argumentLabel;
117
117
switch (initKind) {
@@ -125,8 +125,6 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
125
125
break ;
126
126
}
127
127
128
- nominal->lookupQualified (nominal, DeclNameRef::createConstructor (),
129
- NL_QualifiedDefault, decls);
130
128
for (const auto &decl : decls) {
131
129
auto init = dyn_cast<ConstructorDecl>(decl);
132
130
if (!init || init->getDeclContext () != nominal || init->isGeneric ())
@@ -156,6 +154,14 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
156
154
if (hasExtraneousParam)
157
155
continue ;
158
156
157
+ if (initKind != PropertyWrapperInitKind::Default) {
158
+ if (!argumentParam)
159
+ continue ;
160
+
161
+ if (argumentParam->isInOut () || argumentParam->isVariadic ())
162
+ continue ;
163
+ }
164
+
159
165
// Failable initializers cannot be used.
160
166
if (init->isFailable ()) {
161
167
nonviable.push_back (
@@ -172,12 +178,6 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
172
178
173
179
// Additional checks for initial-value and wrapped-value initializers
174
180
if (initKind != PropertyWrapperInitKind::Default) {
175
- if (!argumentParam)
176
- continue ;
177
-
178
- if (argumentParam->isInOut () || argumentParam->isVariadic ())
179
- continue ;
180
-
181
181
auto paramType = argumentParam->getInterfaceType ();
182
182
if (paramType->is <ErrorType>())
183
183
continue ;
@@ -345,18 +345,22 @@ PropertyWrapperTypeInfoRequest::evaluate(
345
345
if (!valueVar)
346
346
return PropertyWrapperTypeInfo ();
347
347
348
- // FIXME: Remove this one
349
- (void )valueVar->getInterfaceType ();
350
-
348
+ TypeChecker::addImplicitConstructors (nominal);
349
+
350
+ SmallVector<ValueDecl *, 2 > decls;
351
+ nominal->lookupQualified (nominal, DeclNameRef::createConstructor (),
352
+ NL_QualifiedDefault, decls);
353
+
351
354
PropertyWrapperTypeInfo result;
352
355
result.valueVar = valueVar;
353
356
if (auto init = findSuitableWrapperInit (ctx, nominal, valueVar,
354
- PropertyWrapperInitKind::WrappedValue)) {
357
+ PropertyWrapperInitKind::WrappedValue, decls )) {
355
358
result.wrappedValueInit = PropertyWrapperTypeInfo::HasWrappedValueInit;
356
359
result.isWrappedValueInitUsingEscapingAutoClosure =
357
360
isEscapingAutoclosureArgument (init, ctx.Id_wrappedValue );
358
361
} else if (auto init = findSuitableWrapperInit (
359
- ctx, nominal, valueVar, PropertyWrapperInitKind::InitialValue)) {
362
+ ctx, nominal, valueVar, PropertyWrapperInitKind::InitialValue,
363
+ decls)) {
360
364
result.wrappedValueInit = PropertyWrapperTypeInfo::HasInitialValueInit;
361
365
result.isWrappedValueInitUsingEscapingAutoClosure =
362
366
isEscapingAutoclosureArgument (init, ctx.Id_initialValue );
@@ -376,7 +380,7 @@ PropertyWrapperTypeInfoRequest::evaluate(
376
380
}
377
381
378
382
if (findSuitableWrapperInit (ctx, nominal, /* valueVar=*/ nullptr ,
379
- PropertyWrapperInitKind::Default)) {
383
+ PropertyWrapperInitKind::Default, decls )) {
380
384
result.defaultInit = PropertyWrapperTypeInfo::HasDefaultValueInit;
381
385
}
382
386
0 commit comments