@@ -1930,8 +1930,7 @@ SourceLoc OptionalAdjustment::getOptionalityLoc(TypeRepr *tyR) const {
1930
1930
}
1931
1931
1932
1932
// / Classify the provided optionality issues for use in diagnostics.
1933
- // / FIXME: Enumify this
1934
- static unsigned classifyOptionalityIssues (
1933
+ static OptionalAdjustmentPosition classifyOptionalityIssues (
1935
1934
const SmallVectorImpl<OptionalAdjustment> &adjustments,
1936
1935
ValueDecl *requirement) {
1937
1936
unsigned numParameterAdjustments = 0 ;
@@ -1944,21 +1943,20 @@ static unsigned classifyOptionalityIssues(
1944
1943
}
1945
1944
1946
1945
if (hasNonParameterAdjustment) {
1947
- // Both return and parameter adjustments.
1948
1946
if (numParameterAdjustments > 0 )
1949
- return 4 ;
1947
+ return OptionalAdjustmentPosition::ParamAndReturn ;
1950
1948
1951
- // The type of a variable.
1952
1949
if (isa<VarDecl>(requirement))
1953
- return 0 ;
1950
+ return OptionalAdjustmentPosition::VarType ;
1954
1951
1955
- // The result type of something.
1956
- return 1 ;
1952
+ return OptionalAdjustmentPosition::Result;
1957
1953
}
1958
1954
1959
1955
// Only parameter adjustments.
1960
1956
assert (numParameterAdjustments > 0 && " No adjustments?" );
1961
- return numParameterAdjustments == 1 ? 2 : 3 ;
1957
+ return numParameterAdjustments == 1
1958
+ ? OptionalAdjustmentPosition::Param
1959
+ : OptionalAdjustmentPosition::MultipleParam;
1962
1960
}
1963
1961
1964
1962
static void addOptionalityFixIts (
@@ -2078,10 +2076,11 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
2078
2076
2079
2077
case MatchKind::OptionalityConflict: {
2080
2078
auto &adjustments = match.OptionalAdjustments ;
2081
- auto diag = diags.diagnose (match.Witness ,
2079
+ auto issues =
2080
+ static_cast <unsigned >(classifyOptionalityIssues (adjustments, req));
2081
+ auto diag = diags.diagnose (match.Witness ,
2082
2082
diag::protocol_witness_optionality_conflict,
2083
- classifyOptionalityIssues (adjustments, req),
2084
- withAssocTypes);
2083
+ issues, withAssocTypes);
2085
2084
addOptionalityFixIts (adjustments,
2086
2085
match.Witness ->getASTContext (),
2087
2086
match.Witness ,
@@ -3134,14 +3133,14 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3134
3133
auto &diags = ctx.Diags ;
3135
3134
{
3136
3135
SourceLoc diagLoc = getLocForDiagnosingWitness (conformance,witness);
3136
+ auto issues = static_cast <unsigned >(
3137
+ classifyOptionalityIssues (adjustments, requirement));
3137
3138
auto diag = diags.diagnose (
3138
3139
diagLoc,
3139
3140
hasAnyError (adjustments)
3140
- ? diag::err_protocol_witness_optionality
3141
- : diag::warn_protocol_witness_optionality,
3142
- classifyOptionalityIssues (adjustments, requirement),
3143
- witness->getFullName (),
3144
- proto->getFullName ());
3141
+ ? diag::err_protocol_witness_optionality
3142
+ : diag::warn_protocol_witness_optionality,
3143
+ issues, witness->getFullName (), proto->getFullName ());
3145
3144
if (diagLoc == witness->getLoc ()) {
3146
3145
addOptionalityFixIts (adjustments, ctx, witness, diag);
3147
3146
} else {
0 commit comments