@@ -1070,6 +1070,7 @@ static void determineBestChoicesInContext(
1070
1070
Literal = 0x02 ,
1071
1071
ExactOnly = 0x04 ,
1072
1072
DisableCGFloatDoubleConversion = 0x08 ,
1073
+ StringInterpolation = 0x10 ,
1073
1074
};
1074
1075
1075
1076
using MatchOptions = OptionSet<MatchFlag>;
@@ -1177,13 +1178,16 @@ static void determineBestChoicesInContext(
1177
1178
paramType, KnownProtocolKind::ExpressibleByBooleanLiteral))
1178
1179
return 0.3 ;
1179
1180
1180
- if (candidateType->isString () &&
1181
- (TypeChecker::conformsToKnownProtocol (
1182
- paramType, KnownProtocolKind::ExpressibleByStringLiteral) ||
1183
- TypeChecker::conformsToKnownProtocol (
1184
- paramType,
1185
- KnownProtocolKind::ExpressibleByStringInterpolation)))
1186
- return 0.3 ;
1181
+ if (candidateType->isString ()) {
1182
+ auto literalProtocol =
1183
+ options.contains (MatchFlag::StringInterpolation)
1184
+ ? KnownProtocolKind::ExpressibleByStringInterpolation
1185
+ : KnownProtocolKind::ExpressibleByStringLiteral;
1186
+
1187
+ if (TypeChecker::conformsToKnownProtocol (paramType,
1188
+ literalProtocol))
1189
+ return 0.3 ;
1190
+ }
1187
1191
1188
1192
auto &ctx = cs.getASTContext ();
1189
1193
@@ -1523,6 +1527,11 @@ static void determineBestChoicesInContext(
1523
1527
candidate.fromInitializerCall )
1524
1528
options |= MatchFlag::DisableCGFloatDoubleConversion;
1525
1529
1530
+ if (isExpr<InterpolatedStringLiteralExpr>(
1531
+ argumentList->getExpr (argIdx)
1532
+ ->getSemanticsProvidingExpr ()))
1533
+ options |= MatchFlag::StringInterpolation;
1534
+
1526
1535
// The specifier for a candidate only matters for `inout` check.
1527
1536
auto candidateScore = scoreCandidateMatch (
1528
1537
genericSig, decl, candidate.type ->getWithoutSpecifierType (),
0 commit comments