@@ -1184,10 +1184,6 @@ namespace {
1184
1184
assert (ExprStack.back () == expr);
1185
1185
ExprStack.pop_back ();
1186
1186
1187
- // Mark the direct callee as being a callee.
1188
- if (auto *call = dyn_cast<ApplyExpr>(expr))
1189
- markDirectCallee (call->getFn ());
1190
-
1191
1187
// Fold sequence expressions.
1192
1188
if (auto *seqExpr = dyn_cast<SequenceExpr>(expr)) {
1193
1189
auto result = TypeChecker::foldSequence (seqExpr, DC);
@@ -1215,66 +1211,55 @@ namespace {
1215
1211
if (isa<SingleValueStmtExpr>(expr))
1216
1212
SingleValueStmtExprDepth -= 1 ;
1217
1213
1218
- // A 'self.init' or 'super.init' application inside a constructor will
1219
- // evaluate to void, with the initializer's result implicitly rebound
1220
- // to 'self'. Recognize the unresolved constructor expression and
1221
- // determine where to place the RebindSelfInConstructorExpr node.
1222
- // When updating this logic, also update
1223
- // RebindSelfInConstructorExpr::getCalledConstructor.
1224
- auto &ctx = getASTContext ();
1225
- if (auto unresolvedDot = dyn_cast<UnresolvedDotExpr>(expr)) {
1226
- if (auto self = TypeChecker::getSelfForInitDelegationInConstructor (
1227
- DC, unresolvedDot)) {
1214
+ if (auto *apply = dyn_cast<ApplyExpr>(expr)) {
1215
+ // Mark the direct callee as being a callee.
1216
+ markDirectCallee (apply->getFn ());
1217
+
1218
+ // A 'self.init' or 'super.init' application inside a constructor will
1219
+ // evaluate to void, with the initializer's result implicitly rebound
1220
+ // to 'self'. Recognize the unresolved constructor expression and
1221
+ // determine where to place the RebindSelfInConstructorExpr node.
1222
+ //
1223
+ // When updating this logic, also may need to also update
1224
+ // RebindSelfInConstructorExpr::getCalledConstructor.
1225
+ VarDecl *self = nullptr ;
1226
+ if (auto *unresolvedDot =
1227
+ dyn_cast<UnresolvedDotExpr>(apply->getSemanticFn ())) {
1228
+ self = TypeChecker::getSelfForInitDelegationInConstructor (
1229
+ DC, unresolvedDot);
1230
+ }
1231
+
1232
+ if (self) {
1228
1233
// Walk our ancestor expressions looking for the appropriate place
1229
1234
// to insert the RebindSelfInConstructorExpr.
1230
- Expr *target = nullptr ;
1231
- bool foundApply = false ;
1232
- bool foundRebind = false ;
1235
+ Expr *target = apply;
1233
1236
for (auto ancestor : llvm::reverse (ExprStack)) {
1234
- if (isa<RebindSelfInConstructorExpr>(ancestor)) {
1235
- // If we already have a rebind, then we're re-typechecking an
1236
- // expression and are done.
1237
- foundRebind = true ;
1238
- break ;
1239
- }
1240
-
1241
- // Recognize applications.
1242
- if (auto apply = dyn_cast<ApplyExpr>(ancestor)) {
1243
- // If we already saw an application, we're done.
1244
- if (foundApply)
1245
- break ;
1246
-
1247
- // If the function being called is not our unresolved initializer
1248
- // reference, we're done.
1249
- if (apply->getSemanticFn () != unresolvedDot)
1250
- break ;
1251
-
1252
- foundApply = true ;
1237
+ if (isa<IdentityExpr>(ancestor) || isa<ForceValueExpr>(ancestor) ||
1238
+ isa<AnyTryExpr>(ancestor)) {
1253
1239
target = ancestor;
1254
1240
continue ;
1255
1241
}
1256
1242
1257
- // Look through identity, force-value, and 'try' expressions.
1258
- if (isa<IdentityExpr>(ancestor) ||
1259
- isa<ForceValueExpr>(ancestor) ||
1260
- isa<AnyTryExpr>(ancestor)) {
1261
- if (target)
1262
- target = ancestor;
1263
- continue ;
1243
+ if (isa<RebindSelfInConstructorExpr>(ancestor)) {
1244
+ // If we already have a rebind, then we're re-typechecking an
1245
+ // expression and are done.
1246
+ target = nullptr ;
1264
1247
}
1265
1248
1266
1249
// No other expression kinds are permitted.
1267
1250
break ;
1268
1251
}
1269
1252
1270
1253
// If we found a rebind target, note the insertion point.
1271
- if (target && !foundRebind ) {
1254
+ if (target) {
1272
1255
UnresolvedCtorRebindTarget = target;
1273
1256
UnresolvedCtorSelf = self;
1274
1257
}
1275
1258
}
1276
1259
}
1277
1260
1261
+ auto &ctx = getASTContext ();
1262
+
1278
1263
// If the expression we've found is the intended target of an
1279
1264
// RebindSelfInConstructorExpr, wrap it in the
1280
1265
// RebindSelfInConstructorExpr.
0 commit comments