Merge pull request #18465 from slavapestov/protocol-typealias-bug-from-forums

Sema: Fix ConstraintSystem::getTypeOfMemberReference() for protocol typealiases
diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp
index fea5adb..993960b 100644
--- a/lib/Sema/ConstraintSystem.cpp
+++ b/lib/Sema/ConstraintSystem.cpp
@@ -1268,7 +1268,7 @@
   // protocols.
   if (auto *alias = dyn_cast<TypeAliasDecl>(value)) {
     if (baseObjTy->isExistentialType()) {
-      auto memberTy = alias->getDeclaredInterfaceType();
+      auto memberTy = alias->getInterfaceType();
       // If we end up with a protocol typealias here, it's underlying
       // type must be fully concrete.
       assert(!memberTy->hasTypeParameter());
diff --git a/test/Sema/typo_correction.swift b/test/Sema/typo_correction.swift
index ff6668b..549b370 100644
--- a/test/Sema/typo_correction.swift
+++ b/test/Sema/typo_correction.swift
@@ -119,7 +119,7 @@
 protocol P {} // expected-error {{invalid redeclaration of 'P'}}
 
 func hasTypo() {
-  _ = P.a.a // expected-error {{value of type 'Generic' has no member 'a'}}
+  _ = P.a.a // expected-error {{type 'Generic' has no member 'a'}}
 }
 
 // Typo correction with AnyObject.
diff --git a/test/decl/typealias/protocol.swift b/test/decl/typealias/protocol.swift
index b38215d..c78a86b 100644
--- a/test/decl/typealias/protocol.swift
+++ b/test/decl/typealias/protocol.swift
@@ -299,3 +299,19 @@
 protocol UnboundGenericAliasProto {
   typealias G = X
 }
+
+// If pre-checking cannot resolve a member type due to ambiguity,
+// we go down the usual member access path. Make sure its correct
+// for protocol typealiases.
+protocol Amb1 {
+  typealias T = Int
+}
+
+protocol Amb2 {
+  typealias T = String
+}
+
+typealias Amb = Amb1 & Amb2
+
+let _: Int.Type = Amb.T.self
+let _: String.Type = Amb.T.self