@@ -2045,6 +2045,8 @@ namespace {
2045
2045
return diags.diagnose (std::forward<ArgTypes>(Args)...);
2046
2046
}
2047
2047
2048
+ Type diagnoseDisallowedExistential (TypeRepr *repr, Type type);
2049
+
2048
2050
NeverNullType resolveOpenedExistentialArchetype (
2049
2051
TypeAttributes &attrs, TypeRepr *repr,
2050
2052
TypeResolutionOptions options);
@@ -2201,6 +2203,23 @@ Type ResolveTypeRequest::evaluate(Evaluator &evaluator,
2201
2203
return result;
2202
2204
}
2203
2205
2206
+ Type TypeResolver::diagnoseDisallowedExistential (TypeRepr *repr, Type type) {
2207
+ auto options = resolution.getOptions ();
2208
+ if (!(options & TypeResolutionFlags::SilenceErrors) &&
2209
+ options.contains (TypeResolutionFlags::DisallowOpaqueTypes)) {
2210
+ // We're specifically looking at an existential type `any P<some Q>`,
2211
+ // so emit a tailored diagnostic. We don't emit an ErrorType here
2212
+ // for better recovery.
2213
+ diagnose (repr->getLoc (),
2214
+ diag::unsupported_opaque_type_in_existential);
2215
+ // FIXME: We shouldn't have to invalid the type repr here, but not
2216
+ // doing so causes a double-diagnostic.
2217
+ repr->setInvalid ();
2218
+ }
2219
+
2220
+ return type;
2221
+ }
2222
+
2204
2223
NeverNullType TypeResolver::resolveType (TypeRepr *repr,
2205
2224
TypeResolutionOptions options) {
2206
2225
assert (repr && " Cannot validate null TypeReprs!" );
@@ -2245,45 +2264,6 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
2245
2264
case TypeReprKind::SimpleIdent:
2246
2265
case TypeReprKind::GenericIdent:
2247
2266
case TypeReprKind::CompoundIdent: {
2248
- auto *DC = getDeclContext ();
2249
- auto diagnoseDisallowedExistential = [&](Type ty) {
2250
- if (!(options & TypeResolutionFlags::SilenceErrors) &&
2251
- options.contains (TypeResolutionFlags::DisallowOpaqueTypes)) {
2252
- // We're specifically looking at an existential type `any P<some Q>`,
2253
- // so emit a tailored diagnostic. We don't emit an ErrorType here
2254
- // for better recovery.
2255
- diagnose (repr->getLoc (),
2256
- diag::unsupported_opaque_type_in_existential);
2257
- // FIXME: We shouldn't have to invalid the type repr here, but not
2258
- // doing so causes a double-diagnostic.
2259
- repr->setInvalid ();
2260
- }
2261
- return ty;
2262
- };
2263
-
2264
- if (getASTContext ().LangOpts .hasFeature (Feature::ImplicitSome)){
2265
- if (auto opaqueDecl = dyn_cast<OpaqueTypeDecl>(DC)) {
2266
- if (auto ordinal = opaqueDecl->getAnonymousOpaqueParamOrdinal (repr))
2267
- return diagnoseDisallowedExistential (getIdentityOpaqueTypeArchetypeType (opaqueDecl, *ordinal));
2268
- }
2269
-
2270
- // Check whether any of the generic parameters in the context represents
2271
- // this opaque type. If so, return that generic parameter.
2272
- if (options.isConstraintImplicitExistential ()) {
2273
- if (auto declDC = DC->getAsDecl ()) {
2274
- if (auto genericContext = declDC->getAsGenericContext ()) {
2275
- if (auto genericParams = genericContext->getGenericParams ()) {
2276
- for (auto genericParam : *genericParams) {
2277
- if (genericParam->getOpaqueTypeRepr () == repr)
2278
- return diagnoseDisallowedExistential (
2279
- genericParam->getDeclaredInterfaceType ());
2280
- }
2281
- }
2282
- }
2283
- }
2284
- }
2285
- }
2286
-
2287
2267
return resolveIdentifierType (cast<IdentTypeRepr>(repr), options);
2288
2268
}
2289
2269
@@ -2326,25 +2306,10 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
2326
2306
2327
2307
case TypeReprKind::Composition: {
2328
2308
auto *DC = getDeclContext ();
2329
- auto diagnoseDisallowedExistential = [&](Type ty) {
2330
- if (!(options & TypeResolutionFlags::SilenceErrors) &&
2331
- options.contains (TypeResolutionFlags::DisallowOpaqueTypes)) {
2332
- // We're specifically looking at an existential type `any P<some Q>`,
2333
- // so emit a tailored diagnostic. We don't emit an ErrorType here
2334
- // for better recovery.
2335
- diagnose (repr->getLoc (),
2336
- diag::unsupported_opaque_type_in_existential);
2337
- // FIXME: We shouldn't have to invalid the type repr here, but not
2338
- // doing so causes a double-diagnostic.
2339
- repr->setInvalid ();
2340
- }
2341
- return ty;
2342
- };
2343
-
2344
- if (getASTContext ().LangOpts .hasFeature (Feature::ImplicitSome)) {
2309
+ if (getASTContext ().LangOpts .hasFeature (Feature::ImplicitSome)) {
2345
2310
if (auto opaqueDecl = dyn_cast<OpaqueTypeDecl>(DC)) {
2346
2311
if (auto ordinal = opaqueDecl->getAnonymousOpaqueParamOrdinal (repr))
2347
- return diagnoseDisallowedExistential (
2312
+ return diagnoseDisallowedExistential (repr,
2348
2313
getIdentityOpaqueTypeArchetypeType (opaqueDecl, *ordinal));
2349
2314
}
2350
2315
}
@@ -2364,25 +2329,10 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
2364
2329
// This decl is implicit in the source and is created in such contexts by
2365
2330
// evaluation of an `OpaqueResultTypeRequest`.
2366
2331
auto opaqueRepr = cast<OpaqueReturnTypeRepr>(repr);
2367
- auto diagnoseDisallowedExistential = [&](Type ty) {
2368
- if (!(options & TypeResolutionFlags::SilenceErrors) &&
2369
- options.contains (TypeResolutionFlags::DisallowOpaqueTypes)) {
2370
- // We're specifically looking at an existential type `any P<some Q>`,
2371
- // so emit a tailored diagnostic. We don't emit an ErrorType here
2372
- // for better recovery.
2373
- diagnose (opaqueRepr->getOpaqueLoc (),
2374
- diag::unsupported_opaque_type_in_existential);
2375
- // FIXME: We shouldn't have to invalid the type repr here, but not
2376
- // doing so causes a double-diagnostic.
2377
- opaqueRepr->setInvalid ();
2378
- }
2379
- return ty;
2380
- };
2381
-
2382
2332
auto *DC = getDeclContext ();
2383
2333
if (auto opaqueDecl = dyn_cast<OpaqueTypeDecl>(DC)) {
2384
2334
if (auto ordinal = opaqueDecl->getAnonymousOpaqueParamOrdinal (opaqueRepr))
2385
- return diagnoseDisallowedExistential (
2335
+ return diagnoseDisallowedExistential (opaqueRepr,
2386
2336
getIdentityOpaqueTypeArchetypeType (opaqueDecl, *ordinal));
2387
2337
}
2388
2338
@@ -2393,7 +2343,7 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
2393
2343
if (auto genericParams = genericContext->getGenericParams ()) {
2394
2344
for (auto genericParam : *genericParams) {
2395
2345
if (genericParam->getOpaqueTypeRepr () == opaqueRepr)
2396
- return diagnoseDisallowedExistential (
2346
+ return diagnoseDisallowedExistential (opaqueRepr,
2397
2347
genericParam->getDeclaredInterfaceType ());
2398
2348
}
2399
2349
}
@@ -3898,7 +3848,16 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3898
3848
auto *dc = getDeclContext ();
3899
3849
auto &ctx = getASTContext ();
3900
3850
3901
- if (ctx.LangOpts .hasFeature (Feature::ImplicitSome) && options.isConstraintImplicitExistential ()) {
3851
+ if (ctx.LangOpts .hasFeature (Feature::ImplicitSome) &&
3852
+ options.isConstraintImplicitExistential ()) {
3853
+ // Check whether this type is an implicit opaque result type.
3854
+ if (auto *opaqueDecl = dyn_cast<OpaqueTypeDecl>(getDeclContext ())) {
3855
+ if (auto ordinal = opaqueDecl->getAnonymousOpaqueParamOrdinal (IdType)) {
3856
+ return diagnoseDisallowedExistential (IdType,
3857
+ getIdentityOpaqueTypeArchetypeType (opaqueDecl, *ordinal));
3858
+ }
3859
+ }
3860
+
3902
3861
// Check whether any of the generic parameters in the context represents
3903
3862
// this opaque type. If so, return that generic parameter.
3904
3863
if (auto declDC = dc->getAsDecl ()) {
0 commit comments