Merge pull request #11765 from graydon/rdar-34111449-missing-case-in-SILOptimizer-dataflow-diagnostics

[SILOptimizer] Handle a missing case in DataflowDiagnostics.cpp
diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def
index f6a2b3a..2280766 100644
--- a/include/swift/AST/DiagnosticsSema.def
+++ b/include/swift/AST/DiagnosticsSema.def
@@ -1749,6 +1749,10 @@
         "associated type %0 is redundant with type %0 declared in inherited "
         "%1 %2", (DeclName, DescriptiveDeclKind, Type))
 
+ERROR(associated_type_objc,none,
+      "associated type %0 cannot be declared inside '@objc' protocol %1",
+      (DeclName, DeclName))
+
 ERROR(generic_param_access,none,
       "%0 %select{must be declared %select{"
       "%select{private|fileprivate|internal|%error|%error}3|private or fileprivate}4"
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 6cac23f..d7b6d92 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -2720,9 +2720,6 @@
   llvm::SmallPtrSet<Identifier, 4> knownNestedTypes;
   ProtocolType::visitAllProtocols(getConformsTo(),
                                   [&](ProtocolDecl *proto) -> bool {
-    // Objective-C protocols don't have type members.
-    if (proto->isObjC()) return false;
-
     for (auto member : proto->getMembers()) {
       if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
         if (knownNestedTypes.insert(assocType->getName()).second)
diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp
index 2eb6d95..e54e966 100644
--- a/lib/Sema/TypeCheckDecl.cpp
+++ b/lib/Sema/TypeCheckDecl.cpp
@@ -4299,6 +4299,14 @@
   void visitAssociatedTypeDecl(AssociatedTypeDecl *assocType) {
     if (!assocType->hasValidationStarted())
       TC.validateDecl(assocType);
+
+    auto *proto = assocType->getProtocol();
+    if (proto->isObjC()) {
+      TC.diagnose(assocType->getLoc(),
+                  diag::associated_type_objc,
+                  assocType->getName(),
+                  proto->getName());
+    }
   }
 
   void checkUnsupportedNestedType(NominalTypeDecl *NTD) {
diff --git a/test/decl/protocol/req/associated_type_objc.swift b/test/decl/protocol/req/associated_type_objc.swift
new file mode 100644
index 0000000..f7083d9
--- /dev/null
+++ b/test/decl/protocol/req/associated_type_objc.swift
@@ -0,0 +1,10 @@
+// RUN: %target-typecheck-verify-swift -disable-objc-attr-requires-foundation-module
+
+@objc protocol P {
+  associatedtype T
+  // expected-error@-1 {{associated type 'T' cannot be declared inside '@objc' protocol 'P'}}
+}
+
+extension P {
+  func takesT(_: T) {}
+}
diff --git a/test/decl/protocol/req/optional.swift b/test/decl/protocol/req/optional.swift
index 6207ca5..a6d7e5a 100644
--- a/test/decl/protocol/req/optional.swift
+++ b/test/decl/protocol/req/optional.swift
@@ -224,6 +224,7 @@
   optional func foo(_ x: Int) // expected-error{{'optional' requirements are an Objective-C compatibility feature; add '@objc'}}{{3-3=@objc }}
   optional var bar: Int { get } // expected-error{{'optional' requirements are an Objective-C compatibility feature; add '@objc'}}{{3-3=@objc }}
   optional associatedtype Assoc  // expected-error{{'optional' modifier cannot be applied to this declaration}} {{3-12=}}
+  // expected-error@-1 {{associated type 'Assoc' cannot be declared inside '@objc' protocol 'optObjcAttributeProtocol'}}
 }
 
 @objc protocol optionalInitProto {