Skip to content

Commit 792d5e8

Browse files
committed
Sema: Resolve child TypeRepr of @unchecked in the outer TypeResolverContext
Otherwise, '@unchecked Sendable' will wrap the 'Sendable' in an ExistentalType.
1 parent efa055c commit 792d5e8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,23 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
26122612
}
26132613
}
26142614

2615+
if (attrs.has(TAK_unchecked)) {
2616+
ty = resolveType(repr, options);
2617+
if (!ty || ty->hasError()) return ty;
2618+
2619+
if (!options.is(TypeResolverContext::Inherited) ||
2620+
getDeclContext()->getSelfProtocolDecl()) {
2621+
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
2622+
diag::unchecked_not_inheritance_clause);
2623+
} else if (!ty->isConstraintType()) {
2624+
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
2625+
diag::unchecked_not_existential, ty);
2626+
}
2627+
2628+
// Nothing to record in the type. Just clear the attribute.
2629+
attrs.clearAttribute(TAK_unchecked);
2630+
}
2631+
26152632
auto instanceOptions = options;
26162633
instanceOptions.setContext(None);
26172634

@@ -2778,20 +2795,6 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
27782795
}
27792796
}
27802797

2781-
if (attrs.has(TAK_unchecked)) {
2782-
if (!options.is(TypeResolverContext::Inherited) ||
2783-
getDeclContext()->getSelfProtocolDecl()) {
2784-
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
2785-
diag::unchecked_not_inheritance_clause);
2786-
} else if (!ty->isExistentialType()) {
2787-
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
2788-
diag::unchecked_not_existential, ty);
2789-
}
2790-
2791-
// Nothing to record in the type. Just clear the attribute.
2792-
attrs.clearAttribute(TAK_unchecked);
2793-
}
2794-
27952798
for (unsigned i = 0; i != TypeAttrKind::TAK_Count; ++i)
27962799
if (attrs.has((TypeAttrKind)i)) {
27972800
diagnoseInvalid(repr, attrs.getLoc((TypeAttrKind)i),

0 commit comments

Comments
 (0)