Skip to content

Commit e23b373

Browse files
committed
[PropertyWrappers] Add an 'hasExtraneousParam' parameter to simplify control flow
1 parent 370f47c commit e23b373

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,28 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
125125
continue;
126126

127127
ParamDecl *argumentParam = nullptr;
128-
bool allArgsDefault = true;
128+
bool hasExtraneousParam = false;
129129
// Check whether every parameter meets one of the following criteria:
130130
// (1) The parameter has a default argument, or
131131
// (2) The parameter has the given argument label.
132132
for (auto param : *init->getParameters()) {
133133
// Recognize the first parameter with the requested argument label.
134-
if (param->getArgumentName() == argumentLabel && !argumentParam) {
134+
if (!argumentLabel.empty() && param->getArgumentName() == argumentLabel &&
135+
!argumentParam) {
135136
argumentParam = param;
136137
continue;
137138
}
138139

139-
if (param->isDefaultArgument()) {
140-
allArgsDefault &= true;
140+
if (param->isDefaultArgument())
141141
continue;
142-
} else {
143-
// Forget we had a match.
144-
allArgsDefault = false;
145-
argumentParam = nullptr;
146-
break;
147-
}
148-
}
149142

150-
if (initKind != PropertyWrapperInitKind::Default && !argumentParam)
151-
continue;
143+
// Skip this init as the param doesn't meet the above criteria
144+
hasExtraneousParam = true;
145+
break;
146+
}
152147

153-
if (initKind == PropertyWrapperInitKind::Default && !allArgsDefault) {
148+
if (hasExtraneousParam)
154149
continue;
155-
}
156150

157151
// Failable initializers cannot be used.
158152
if (init->isFailable()) {

0 commit comments

Comments
 (0)