Skip to content

Commit afc916e

Browse files
committed
[Type checker] Make DependentGenericTypeResolver::areSameType() more reasonable.
If the structure of the types matches, consider the types to be the same. This implementation is from ProtocolRequirementTypeResolver::areSameType().
1 parent 70bdea4 commit afc916e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ Type DependentGenericTypeResolver::resolveDependentMemberType(
4343
}
4444

4545
bool DependentGenericTypeResolver::areSameType(Type type1, Type type2) {
46-
if (!type1->hasTypeParameter() && !type2->hasTypeParameter())
47-
return type1->isEqual(type2);
46+
if (type1->isEqual(type2))
47+
return true;
48+
49+
// If both refer to associated types with the same name, they'll implicitly
50+
// be considered equivalent.
51+
auto depMem1 = type1->getAs<DependentMemberType>();
52+
if (!depMem1) return false;
4853

49-
// Conservative answer: they could be the same.
50-
return true;
54+
auto depMem2 = type2->getAs<DependentMemberType>();
55+
if (!depMem2) return false;
56+
57+
if (depMem1->getName() != depMem2->getName()) return false;
58+
59+
return areSameType(depMem1->getBase(), depMem2->getBase());
5160
}
5261

5362
Type GenericTypeToArchetypeResolver::mapTypeIntoContext(Type type) {

0 commit comments

Comments
 (0)