@@ -92,6 +92,32 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
92
92
}
93
93
}
94
94
95
+ static bool
96
+ isUnviableDefaultType (Type defaultType,
97
+ llvm::SmallPtrSetImpl<CanType> &existingTypes) {
98
+ auto canType = defaultType->getCanonicalType ();
99
+
100
+ if (!defaultType->hasUnboundGenericType ())
101
+ return !existingTypes.insert (canType).second ;
102
+
103
+ // For generic literal types, check whether we already have a
104
+ // specialization of this generic within our list.
105
+ // FIXME: This assumes that, e.g., the default literal
106
+ // int/float/char/string types are never generic.
107
+ auto nominal = defaultType->getAnyNominal ();
108
+ if (!nominal)
109
+ return true ;
110
+
111
+ if (llvm::any_of (existingTypes, [&nominal](CanType existingType) {
112
+ // FIXME: Check parents?
113
+ return nominal == existingType->getAnyNominal ();
114
+ }))
115
+ return true ;
116
+
117
+ existingTypes.insert (canType);
118
+ return false ;
119
+ }
120
+
95
121
void ConstraintSystem::PotentialBindings::inferDefaultTypes (
96
122
ConstraintSystem &cs, llvm::SmallPtrSetImpl<CanType> &existingTypes) {
97
123
// If we have any literal constraints, check whether there is already a
@@ -165,7 +191,7 @@ void ConstraintSystem::PotentialBindings::inferDefaultTypes(
165
191
if (!defaultType)
166
192
continue ;
167
193
168
- if (!existingTypes. insert (defaultType-> getCanonicalType ()). second )
194
+ if (isUnviableDefaultType (defaultType, existingTypes) )
169
195
continue ;
170
196
171
197
// We need to figure out whether this is a direct conformance
0 commit comments