@@ -2109,104 +2109,6 @@ namespace {
2109
2109
return expr;
2110
2110
}
2111
2111
2112
- Expr *visitUnresolvedConstructorExpr (UnresolvedConstructorExpr *expr) {
2113
- // Resolve the callee to the constructor declaration selected.
2114
- auto ctorLocator = cs.getConstraintLocator (
2115
- expr,
2116
- ConstraintLocator::ConstructorMember);
2117
-
2118
- auto selected = getOverloadChoiceIfAvailable (ctorLocator);
2119
-
2120
- // If we didn't form a ConstructorMember constraint, then it
2121
- // acts like a normal member reference to '.init'.
2122
- if (!selected) {
2123
- return applyMemberRefExpr (expr, expr->getSubExpr (), expr->getDotLoc (),
2124
- expr->getConstructorLoc (), expr->isImplicit ());
2125
- }
2126
-
2127
-
2128
- auto choice = selected->choice ;
2129
- auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
2130
-
2131
- auto arg = expr->getSubExpr ()->getSemanticsProvidingExpr ();
2132
- auto &tc = cs.getTypeChecker ();
2133
-
2134
- // If the subexpression is a metatype, build a direct reference to the
2135
- // constructor.
2136
- if (arg->getType ()->is <AnyMetatypeType>()) {
2137
- return buildMemberRef (expr->getSubExpr (),
2138
- selected->openedFullType ,
2139
- expr->getDotLoc (),
2140
- ctor,
2141
- expr->getConstructorLoc (),
2142
- expr->getType (),
2143
- ConstraintLocatorBuilder (
2144
- cs.getConstraintLocator (expr)),
2145
- ctorLocator,
2146
- expr->isImplicit (),
2147
- AccessSemantics::Ordinary,
2148
- /* isDynamic=*/ false );
2149
- }
2150
-
2151
- // The subexpression must be either 'self' or 'super'.
2152
- if (!arg->isSuperExpr ()) {
2153
- // 'super' references have already been fully checked; handle the
2154
- // 'self' case below.
2155
- bool diagnoseBadInitRef = true ;
2156
- if (auto dre = dyn_cast<DeclRefExpr>(arg)) {
2157
- if (dre->getDecl ()->getName () == cs.getASTContext ().Id_self ) {
2158
- // We have a reference to 'self'.
2159
- diagnoseBadInitRef = false ;
2160
-
2161
- // Make sure the reference to 'self' occurs within an initializer.
2162
- if (!dyn_cast_or_null<ConstructorDecl>(
2163
- cs.DC ->getInnermostMethodContext ())) {
2164
- if (!SuppressDiagnostics)
2165
- tc.diagnose (expr->getDotLoc (),
2166
- diag::init_delegation_outside_initializer);
2167
- return nullptr ;
2168
- }
2169
- }
2170
- }
2171
-
2172
- // If we need to diagnose this as a bad reference to an initializer,
2173
- // do so now.
2174
- if (diagnoseBadInitRef) {
2175
- // Determine whether 'super' would have made sense as a base.
2176
- bool hasSuper = false ;
2177
- if (auto func = cs.DC ->getInnermostMethodContext ()) {
2178
- if (auto nominalType
2179
- = func->getDeclContext ()->getDeclaredTypeOfContext ()) {
2180
- if (auto classDecl = nominalType->getClassOrBoundGenericClass ()) {
2181
- hasSuper = classDecl->hasSuperclass ();
2182
- }
2183
- }
2184
- }
2185
-
2186
- if (SuppressDiagnostics)
2187
- return nullptr ;
2188
-
2189
- tc.diagnose (expr->getDotLoc (), diag::bad_init_ref_base, hasSuper);
2190
- }
2191
- }
2192
-
2193
- // Build a partial application of the delegated initializer.
2194
- Expr *ctorRef = buildOtherConstructorRef (
2195
- selected->openedFullType ,
2196
- ctor, expr->getConstructorLoc (),
2197
- cs.getConstraintLocator (
2198
- expr,
2199
- ConstraintLocator::ConstructorMember),
2200
- expr->isImplicit ());
2201
- auto *call
2202
- = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef,
2203
- expr->getDotLoc (),
2204
- expr->getSubExpr ());
2205
- return finishApply (call, expr->getType (),
2206
- ConstraintLocatorBuilder (
2207
- cs.getConstraintLocator (expr)));
2208
- }
2209
-
2210
2112
Expr *visitDotSyntaxBaseIgnoredExpr (DotSyntaxBaseIgnoredExpr *expr) {
2211
2113
return simplifyExprType (expr);
2212
2114
}
@@ -2352,9 +2254,91 @@ namespace {
2352
2254
// / A list of optional injections that have been diagnosed.
2353
2255
llvm::SmallPtrSet<InjectIntoOptionalExpr *, 4 > DiagnosedOptionalInjections;
2354
2256
private:
2257
+ // / Create a member reference to the given constructor.
2258
+ Expr *applyCtorRefExpr (Expr *expr, Expr *base, SourceLoc dotLoc,
2259
+ SourceLoc nameLoc, bool implicit,
2260
+ ConstraintLocator *ctorLocator,
2261
+ ConstructorDecl *ctor,
2262
+ Type openedType) {
2263
+ // If the subexpression is a metatype, build a direct reference to the
2264
+ // constructor.
2265
+ if (base->getType ()->is <AnyMetatypeType>()) {
2266
+ return buildMemberRef (base, openedType, dotLoc, ctor, nameLoc,
2267
+ expr->getType (),
2268
+ ConstraintLocatorBuilder (
2269
+ cs.getConstraintLocator (expr)),
2270
+ ctorLocator,
2271
+ implicit,
2272
+ AccessSemantics::Ordinary,
2273
+ /* isDynamic=*/ false );
2274
+ }
2275
+
2276
+ // The subexpression must be either 'self' or 'super'.
2277
+ if (!base->isSuperExpr ()) {
2278
+ // 'super' references have already been fully checked; handle the
2279
+ // 'self' case below.
2280
+ auto &tc = cs.getTypeChecker ();
2281
+ bool diagnoseBadInitRef = true ;
2282
+ auto arg = base->getSemanticsProvidingExpr ();
2283
+ if (auto dre = dyn_cast<DeclRefExpr>(arg)) {
2284
+ if (dre->getDecl ()->getName () == cs.getASTContext ().Id_self ) {
2285
+ // We have a reference to 'self'.
2286
+ diagnoseBadInitRef = false ;
2287
+
2288
+ // Make sure the reference to 'self' occurs within an initializer.
2289
+ if (!dyn_cast_or_null<ConstructorDecl>(
2290
+ cs.DC ->getInnermostMethodContext ())) {
2291
+ if (!SuppressDiagnostics)
2292
+ tc.diagnose (dotLoc, diag::init_delegation_outside_initializer);
2293
+ return nullptr ;
2294
+ }
2295
+ }
2296
+ }
2297
+
2298
+ // If we need to diagnose this as a bad reference to an initializer,
2299
+ // do so now.
2300
+ if (diagnoseBadInitRef) {
2301
+ // Determine whether 'super' would have made sense as a base.
2302
+ bool hasSuper = false ;
2303
+ if (auto func = cs.DC ->getInnermostMethodContext ()) {
2304
+ if (auto nominalType
2305
+ = func->getDeclContext ()->getDeclaredTypeOfContext ()) {
2306
+ if (auto classDecl = nominalType->getClassOrBoundGenericClass ()) {
2307
+ hasSuper = classDecl->hasSuperclass ();
2308
+ }
2309
+ }
2310
+ }
2311
+
2312
+ if (SuppressDiagnostics)
2313
+ return nullptr ;
2314
+
2315
+ tc.diagnose (dotLoc, diag::bad_init_ref_base, hasSuper);
2316
+ }
2317
+ }
2318
+
2319
+ // Build a partial application of the delegated initializer.
2320
+ Expr *ctorRef = buildOtherConstructorRef (openedType, ctor, nameLoc,
2321
+ ctorLocator, implicit);
2322
+ auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
2323
+ base);
2324
+ return finishApply (call, expr->getType (),
2325
+ ConstraintLocatorBuilder (
2326
+ cs.getConstraintLocator (expr)));
2327
+ }
2355
2328
2356
2329
Expr *applyMemberRefExpr (Expr *expr, Expr *base, SourceLoc dotLoc,
2357
2330
SourceLoc nameLoc, bool implicit) {
2331
+ // If we have a constructor member, handle it as a constructor.
2332
+ auto ctorLocator = cs.getConstraintLocator (
2333
+ expr,
2334
+ ConstraintLocator::ConstructorMember);
2335
+ if (auto selected = getOverloadChoiceIfAvailable (ctorLocator)) {
2336
+ auto choice = selected->choice ;
2337
+ auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
2338
+ return applyCtorRefExpr (expr, base, dotLoc, nameLoc, implicit,
2339
+ ctorLocator, ctor, selected->openedFullType );
2340
+ }
2341
+
2358
2342
// Determine the declaration selected for this overloaded reference.
2359
2343
auto memberLocator = cs.getConstraintLocator (expr,
2360
2344
ConstraintLocator::Member);
0 commit comments