@@ -2655,27 +2655,37 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2655
2655
2656
2656
void checkUnsupportedNestedType (NominalTypeDecl *NTD) {
2657
2657
auto *DC = NTD->getDeclContext ();
2658
+
2659
+ // We don't allow nested types inside inlinable contexts.
2658
2660
auto kind = DC->getFragileFunctionKind ();
2659
2661
if (kind.kind != FragileFunctionKind::None) {
2660
2662
NTD->diagnose (diag::local_type_in_inlinable_function, NTD->getName (),
2661
2663
kind.getSelector ());
2662
2664
}
2663
2665
2664
- // We don't support protocols outside the top level of a file.
2665
- if (isa<ProtocolDecl>(NTD) &&
2666
- !NTD->getParent ()->isModuleScopeContext ()) {
2667
- NTD->diagnose (diag::unsupported_nested_protocol, NTD);
2668
- NTD->setInvalid ();
2669
- return ;
2670
- }
2666
+ if (auto *parentDecl = DC->getSelfNominalTypeDecl ()) {
2667
+ // We don't allow types to be nested within a tuple extension.
2668
+ if (isa<BuiltinTupleDecl>(parentDecl)) {
2669
+ NTD->diagnose (diag::tuple_extension_nested_type, NTD);
2670
+ return ;
2671
+ }
2671
2672
2672
- // We don't support nested types in protocols.
2673
- if (auto proto = DC->getSelfProtocolDecl ()) {
2674
- if (DC->getExtendedProtocolDecl ()) {
2675
- NTD->diagnose (diag::unsupported_type_nested_in_protocol_extension, NTD,
2676
- proto);
2677
- } else {
2678
- NTD->diagnose (diag::unsupported_type_nested_in_protocol, NTD, proto);
2673
+ // We don't support protocols outside the top level of a file.
2674
+ if (isa<ProtocolDecl>(NTD) &&
2675
+ !DC->isModuleScopeContext ()) {
2676
+ NTD->diagnose (diag::unsupported_nested_protocol, NTD);
2677
+ NTD->setInvalid ();
2678
+ return ;
2679
+ }
2680
+
2681
+ // We don't support nested types in protocols.
2682
+ if (auto proto = dyn_cast<ProtocolDecl>(parentDecl)) {
2683
+ if (DC->getExtendedProtocolDecl ()) {
2684
+ NTD->diagnose (diag::unsupported_type_nested_in_protocol_extension, NTD,
2685
+ proto);
2686
+ } else {
2687
+ NTD->diagnose (diag::unsupported_type_nested_in_protocol, NTD, proto);
2688
+ }
2679
2689
}
2680
2690
}
2681
2691
0 commit comments