@@ -1031,28 +1031,32 @@ void BindingSet::determineLiteralCoverage() {
10311031 }
10321032}
10331033
1034- void BindingSet::addLiteralRequirement (Constraint *constraint) {
1035- auto *protocol = constraint->getProtocol ();
1034+ void BindingSet::coalesceIntegerAndFloatLiteralRequirements () {
1035+ for (const auto &pair : Literals) {
1036+ auto *protocol = pair.first ;
10361037
1037- // Let's try to coalesce integer and floating point literal protocols
1038- // if they appear together because the only possible default type that
1039- // could satisfy both requirements is `Double`.
1040- {
10411038 if (protocol->isSpecificProtocol (
10421039 KnownProtocolKind::ExpressibleByIntegerLiteral)) {
10431040 auto *floatLiteral = CS.getASTContext ().getProtocol (
10441041 KnownProtocolKind::ExpressibleByFloatLiteral);
1045- if (Literals.count (floatLiteral))
1042+ if (Literals.count (floatLiteral)) {
1043+ Literals.erase (protocol);
10461044 return ;
1045+ }
10471046 }
10481047
10491048 if (protocol->isSpecificProtocol (
10501049 KnownProtocolKind::ExpressibleByFloatLiteral)) {
10511050 auto *intLiteral = CS.getASTContext ().getProtocol (
10521051 KnownProtocolKind::ExpressibleByIntegerLiteral);
10531052 Literals.erase (intLiteral);
1053+ return ;
10541054 }
10551055 }
1056+ }
1057+
1058+ void BindingSet::addLiteralRequirement (Constraint *constraint) {
1059+ auto *protocol = constraint->getProtocol ();
10561060
10571061 if (Literals.count (protocol) > 0 )
10581062 return ;
@@ -1235,6 +1239,9 @@ const BindingSet *ConstraintSystem::determineBestBindings(
12351239 bestBindings = &bindings;
12361240 }
12371241
1242+ if (bestBindings)
1243+ bestBindings->coalesceIntegerAndFloatLiteralRequirements ();
1244+
12381245 return bestBindings;
12391246}
12401247
@@ -1667,6 +1674,7 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar) {
16671674 (void ) bindings.finalizeKeyPathBindings ();
16681675 bindings.finalizeUnresolvedMemberChainResult ();
16691676 bindings.determineLiteralCoverage ();
1677+ bindings.coalesceIntegerAndFloatLiteralRequirements ();
16701678
16711679 return bindings;
16721680}
0 commit comments