@@ -1924,6 +1924,10 @@ namespace {
1924
1924
return diags.diagnose (std::forward<ArgTypes>(Args)...);
1925
1925
}
1926
1926
1927
+ NeverNullType resolveOpenedExistentialArchetype (
1928
+ TypeAttributes &attrs, TypeRepr *repr,
1929
+ TypeResolutionOptions options);
1930
+
1927
1931
NeverNullType resolveAttributedType (AttributedTypeRepr *repr,
1928
1932
TypeResolutionOptions options);
1929
1933
NeverNullType resolveAttributedType (TypeAttributes &attrs, TypeRepr *repr,
@@ -2307,6 +2311,29 @@ TypeResolver::resolveAttributedType(AttributedTypeRepr *repr,
2307
2311
return resolveAttributedType (attrs, repr->getTypeRepr (), options);
2308
2312
}
2309
2313
2314
+ // / In SIL, handle @opened (n), which creates an existential archetype.
2315
+ NeverNullType
2316
+ TypeResolver::resolveOpenedExistentialArchetype (
2317
+ TypeAttributes &attrs, TypeRepr *repr,
2318
+ TypeResolutionOptions options) {
2319
+ options.setContext (None);
2320
+ Type ty = resolveType (repr, options);
2321
+
2322
+ if (!ty->isExistentialType ()) {
2323
+ diagnoseInvalid (repr, attrs.getLoc (TAK_opened), diag::opened_non_protocol,
2324
+ ty);
2325
+ } else {
2326
+ ty = GenericEnvironment::mapTypeIntoContext (
2327
+ resolution.getGenericSignature ().getGenericEnvironment (), ty);
2328
+ ty = OpenedArchetypeType::get (ty->getCanonicalType (),
2329
+ GenericSignature (),
2330
+ attrs.OpenedID );
2331
+ }
2332
+ attrs.clearAttribute (TAK_opened);
2333
+
2334
+ return ty;
2335
+ }
2336
+
2310
2337
NeverNullType
2311
2338
TypeResolver::resolveAttributedType (TypeAttributes &attrs, TypeRepr *repr,
2312
2339
TypeResolutionOptions options) {
@@ -2715,6 +2742,10 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
2715
2742
attrs.clearAttribute (TAK_unchecked);
2716
2743
}
2717
2744
2745
+ if (attrs.has (TAK_opened)) {
2746
+ ty = resolveOpenedExistentialArchetype (attrs, repr, options);
2747
+ }
2748
+
2718
2749
auto instanceOptions = options;
2719
2750
instanceOptions.setContext (None);
2720
2751
@@ -2834,21 +2865,6 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
2834
2865
attrs.clearAttribute (TAK_noDerivative);
2835
2866
}
2836
2867
2837
- // In SIL, handle @opened (n), which creates an existential archetype.
2838
- if (attrs.has (TAK_opened)) {
2839
- if (!ty->isExistentialType ()) {
2840
- diagnoseInvalid (repr, attrs.getLoc (TAK_opened), diag::opened_non_protocol,
2841
- ty);
2842
- } else {
2843
- ty = GenericEnvironment::mapTypeIntoContext (
2844
- resolution.getGenericSignature ().getGenericEnvironment (), ty);
2845
- ty = OpenedArchetypeType::get (ty->getCanonicalType (),
2846
- resolution.getGenericSignature (),
2847
- attrs.OpenedID );
2848
- }
2849
- attrs.clearAttribute (TAK_opened);
2850
- }
2851
-
2852
2868
// In SIL files *only*, permit @weak and @unowned to apply directly to types.
2853
2869
if (attrs.hasOwnership ()) {
2854
2870
if (auto SF = getDeclContext ()->getParentSourceFile ()) {
0 commit comments