@@ -4143,66 +4143,59 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4143
4143
}
4144
4144
4145
4145
void visitPatternBindingDecl (PatternBindingDecl *PBD) {
4146
- // Check all the pattern/init pairs in the PBD.
4147
- validatePatternBindingEntries (TC, PBD) ;
4146
+ if (!IsFirstPass)
4147
+ return ;
4148
4148
4149
4149
if (PBD->isBeingValidated ())
4150
4150
return ;
4151
4151
4152
- // If the initializers in the PBD aren't checked yet, do so now.
4153
- if (!IsFirstPass) {
4154
- for (unsigned i = 0 , e = PBD->getNumPatternEntries (); i != e; ++i) {
4155
- if (!PBD->isInitializerChecked (i) && PBD->getInit (i))
4156
- TC.typeCheckPatternBinding (PBD, i, /* skipApplyingSolution*/ false );
4157
- }
4158
- }
4152
+ // Check all the pattern/init pairs in the PBD.
4153
+ validatePatternBindingEntries (TC, PBD);
4159
4154
4160
4155
TC.checkDeclAttributesEarly (PBD);
4161
4156
4162
- if (IsFirstPass) {
4163
- for (unsigned i = 0 , e = PBD->getNumPatternEntries (); i != e; ++i) {
4164
- // Type check each VarDecl that this PatternBinding handles.
4165
- visitBoundVars (PBD->getPattern (i));
4157
+ for (unsigned i = 0 , e = PBD->getNumPatternEntries (); i != e; ++i) {
4158
+ // Type check each VarDecl that this PatternBinding handles.
4159
+ visitBoundVars (PBD->getPattern (i));
4166
4160
4167
- // If we have a type but no initializer, check whether the type is
4168
- // default-initializable. If so, do it.
4169
- if (PBD->getPattern (i)->hasType () &&
4170
- !PBD->getInit (i) &&
4171
- PBD->getPattern (i)->hasStorage () &&
4172
- !PBD->getPattern (i)->getType ()->hasError ()) {
4161
+ // If we have a type but no initializer, check whether the type is
4162
+ // default-initializable. If so, do it.
4163
+ if (PBD->getPattern (i)->hasType () &&
4164
+ !PBD->getInit (i) &&
4165
+ PBD->getPattern (i)->hasStorage () &&
4166
+ !PBD->getPattern (i)->getType ()->hasError ()) {
4173
4167
4174
- // If we have a type-adjusting attribute (like ownership), apply it now.
4175
- if (auto var = PBD->getSingleVar ())
4176
- TC.checkTypeModifyingDeclAttributes (var);
4168
+ // If we have a type-adjusting attribute (like ownership), apply it now.
4169
+ if (auto var = PBD->getSingleVar ())
4170
+ TC.checkTypeModifyingDeclAttributes (var);
4177
4171
4178
- // Decide whether we should suppress default initialization.
4179
- //
4180
- // Note: Swift 4 had a bug where properties with a desugared optional
4181
- // type like Optional<Int> had a half-way behavior where sometimes
4182
- // they behave like they are default initialized, and sometimes not.
4183
- //
4184
- // In Swift 5 mode, use the right condition here, and only default
4185
- // initialize properties with a sugared Optional type.
4186
- //
4187
- // (The restriction to sugared types only comes because we don't have
4188
- // the iterative declaration checker yet; so in general, we cannot
4189
- // look at the type of a property at all, and can only look at the
4190
- // TypeRepr, because we haven't validated the property yet.)
4191
- if (TC.Context .isSwiftVersionAtLeast (5 )) {
4192
- if (!PBD->isDefaultInitializable (i))
4193
- continue ;
4194
- } else {
4195
- if (PBD->getPattern (i)->isNeverDefaultInitializable ())
4196
- continue ;
4197
- }
4172
+ // Decide whether we should suppress default initialization.
4173
+ //
4174
+ // Note: Swift 4 had a bug where properties with a desugared optional
4175
+ // type like Optional<Int> had a half-way behavior where sometimes
4176
+ // they behave like they are default initialized, and sometimes not.
4177
+ //
4178
+ // In Swift 5 mode, use the right condition here, and only default
4179
+ // initialize properties with a sugared Optional type.
4180
+ //
4181
+ // (The restriction to sugared types only comes because we don't have
4182
+ // the iterative declaration checker yet; so in general, we cannot
4183
+ // look at the type of a property at all, and can only look at the
4184
+ // TypeRepr, because we haven't validated the property yet.)
4185
+ if (TC.Context .isSwiftVersionAtLeast (5 )) {
4186
+ if (!PBD->isDefaultInitializable (i))
4187
+ continue ;
4188
+ } else {
4189
+ if (PBD->getPattern (i)->isNeverDefaultInitializable ())
4190
+ continue ;
4191
+ }
4198
4192
4199
- auto type = PBD->getPattern (i)->getType ();
4200
- if (auto defaultInit = buildDefaultInitializer (TC, type)) {
4201
- // If we got a default initializer, install it and re-type-check it
4202
- // to make sure it is properly coerced to the pattern type.
4203
- PBD->setInit (i, defaultInit);
4204
- TC.typeCheckPatternBinding (PBD, i, /* skipApplyingSolution*/ false );
4205
- }
4193
+ auto type = PBD->getPattern (i)->getType ();
4194
+ if (auto defaultInit = buildDefaultInitializer (TC, type)) {
4195
+ // If we got a default initializer, install it and re-type-check it
4196
+ // to make sure it is properly coerced to the pattern type.
4197
+ PBD->setInit (i, defaultInit);
4198
+ TC.typeCheckPatternBinding (PBD, i, /* skipApplyingSolution*/ false );
4206
4199
}
4207
4200
}
4208
4201
}
@@ -4269,9 +4262,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4269
4262
}
4270
4263
4271
4264
TC.checkDeclAttributes (PBD);
4265
+ checkAccessControl (TC, PBD);
4272
4266
4273
- if (IsFirstPass)
4274
- checkAccessControl (TC, PBD);
4267
+ // If the initializers in the PBD aren't checked yet, do so now.
4268
+ for (unsigned i = 0 , e = PBD->getNumPatternEntries (); i != e; ++i) {
4269
+ if (!PBD->isInitializerChecked (i) && PBD->getInit (i))
4270
+ TC.typeCheckPatternBinding (PBD, i, /* skipApplyingSolution*/ false );
4271
+ }
4275
4272
}
4276
4273
4277
4274
void visitSubscriptDecl (SubscriptDecl *SD) {
0 commit comments