@@ -2243,8 +2243,30 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
2243
2243
options);
2244
2244
case TypeReprKind::SimpleIdent:
2245
2245
case TypeReprKind::GenericIdent:
2246
- case TypeReprKind::CompoundIdent:
2247
- return resolveIdentifierType (cast<IdentTypeRepr>(repr), options);
2246
+ case TypeReprKind::CompoundIdent: {
2247
+ auto *DC = getDeclContext();
2248
+ auto diagnoseDisallowedExistential = [&](Type ty) {
2249
+ if (!(options & TypeResolutionFlags::SilenceErrors) &&
2250
+ options.contains(TypeResolutionFlags::DisallowOpaqueTypes)) {
2251
+ // We're specifically looking at an existential type `any P<some Q>`,
2252
+ // so emit a tailored diagnostic. We don't emit an ErrorType here
2253
+ // for better recovery.
2254
+ diagnose(repr->getLoc(),
2255
+ diag::unsupported_opaque_type_in_existential);
2256
+ // FIXME: We shouldn't have to invalid the type repr here, but not
2257
+ // doing so causes a double-diagnostic.
2258
+ repr->setInvalid();
2259
+ }
2260
+ return ty;
2261
+ };
2262
+
2263
+ if (auto opaqueDecl = dyn_cast<OpaqueTypeDecl>(DC)) {
2264
+ if (auto ordinal = opaqueDecl->getAnonymousOpaqueParamOrdinal(repr))
2265
+ return diagnoseDisallowedExistential(getIdentityOpaqueTypeArchetypeType(opaqueDecl, *ordinal));
2266
+ } else {
2267
+ return resolveIdentifierType(cast<IdentTypeRepr>(repr), options);
2268
+ }
2269
+ }
2248
2270
2249
2271
case TypeReprKind::Function: {
2250
2272
if (!(options & TypeResolutionFlags::SILType)) {
@@ -3825,7 +3847,7 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3825
3847
auto *dc = getDeclContext();
3826
3848
auto &ctx = getASTContext();
3827
3849
3828
- if ( ctx.LangOpts .hasFeature (Feature::ImplicitSome) & ! options.is (TypeResolverContext::Inherited) ) {
3850
+ if (ctx.LangOpts.hasFeature(Feature::ImplicitSome) && options.isConstraintImplicitExistential()) {
3829
3851
// Check whether any of the generic parameters in the context represents
3830
3852
// this opaque type. If so, return that generic parameter.
3831
3853
if (auto declDC = dc->getAsDecl()) {
0 commit comments