@@ -1927,9 +1927,29 @@ SourceLoc OptionalAdjustment::getOptionalityLoc(TypeRepr *tyR) const {
1927
1927
return SourceLoc ();
1928
1928
}
1929
1929
1930
+ namespace {
1931
+ // / Describes the position for optional adjustment made to a witness.
1932
+ // /
1933
+ // / This is used by the following diagnostics:
1934
+ // / 1) 'err_protocol_witness_optionality',
1935
+ // / 2) 'warn_protocol_witness_optionality'
1936
+ // / 3) 'protocol_witness_optionality_conflict'
1937
+ enum class OptionalAdjustmentPosition : unsigned {
1938
+ // / The type of a variable.
1939
+ VarType = 0 ,
1940
+ // / The result type of something.
1941
+ Result = 1 ,
1942
+ // / The parameter type of something.
1943
+ Param = 2 ,
1944
+ // / The parameter types of something.
1945
+ MultipleParam = 3 ,
1946
+ // / Both return and parameter adjustments.
1947
+ ParamAndReturn = 4 ,
1948
+ };
1949
+ } // end anonymous namespace
1950
+
1930
1951
// / Classify the provided optionality issues for use in diagnostics.
1931
- // / FIXME: Enumify this
1932
- static unsigned classifyOptionalityIssues (
1952
+ static OptionalAdjustmentPosition classifyOptionalityIssues (
1933
1953
const SmallVectorImpl<OptionalAdjustment> &adjustments,
1934
1954
ValueDecl *requirement) {
1935
1955
unsigned numParameterAdjustments = 0 ;
@@ -1942,21 +1962,20 @@ static unsigned classifyOptionalityIssues(
1942
1962
}
1943
1963
1944
1964
if (hasNonParameterAdjustment) {
1945
- // Both return and parameter adjustments.
1946
1965
if (numParameterAdjustments > 0 )
1947
- return 4 ;
1966
+ return OptionalAdjustmentPosition::ParamAndReturn ;
1948
1967
1949
- // The type of a variable.
1950
1968
if (isa<VarDecl>(requirement))
1951
- return 0 ;
1969
+ return OptionalAdjustmentPosition::VarType ;
1952
1970
1953
- // The result type of something.
1954
- return 1 ;
1971
+ return OptionalAdjustmentPosition::Result;
1955
1972
}
1956
1973
1957
1974
// Only parameter adjustments.
1958
1975
assert (numParameterAdjustments > 0 && " No adjustments?" );
1959
- return numParameterAdjustments == 1 ? 2 : 3 ;
1976
+ return numParameterAdjustments == 1
1977
+ ? OptionalAdjustmentPosition::Param
1978
+ : OptionalAdjustmentPosition::MultipleParam;
1960
1979
}
1961
1980
1962
1981
static void addOptionalityFixIts (
@@ -2076,10 +2095,11 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
2076
2095
2077
2096
case MatchKind::OptionalityConflict: {
2078
2097
auto &adjustments = match.OptionalAdjustments ;
2079
- auto diag = diags.diagnose (match.Witness ,
2098
+ auto issues =
2099
+ static_cast <unsigned >(classifyOptionalityIssues (adjustments, req));
2100
+ auto diag = diags.diagnose (match.Witness ,
2080
2101
diag::protocol_witness_optionality_conflict,
2081
- classifyOptionalityIssues (adjustments, req),
2082
- withAssocTypes);
2102
+ issues, withAssocTypes);
2083
2103
addOptionalityFixIts (adjustments,
2084
2104
match.Witness ->getASTContext (),
2085
2105
match.Witness ,
@@ -3167,14 +3187,14 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3167
3187
auto &diags = ctx.Diags ;
3168
3188
{
3169
3189
SourceLoc diagLoc = getLocForDiagnosingWitness (conformance,witness);
3190
+ auto issues = static_cast <unsigned >(
3191
+ classifyOptionalityIssues (adjustments, requirement));
3170
3192
auto diag = diags.diagnose (
3171
3193
diagLoc,
3172
3194
hasAnyError (adjustments)
3173
- ? diag::err_protocol_witness_optionality
3174
- : diag::warn_protocol_witness_optionality,
3175
- classifyOptionalityIssues (adjustments, requirement),
3176
- witness->getFullName (),
3177
- proto->getFullName ());
3195
+ ? diag::err_protocol_witness_optionality
3196
+ : diag::warn_protocol_witness_optionality,
3197
+ issues, witness->getFullName (), proto->getFullName ());
3178
3198
if (diagLoc == witness->getLoc ()) {
3179
3199
addOptionalityFixIts (adjustments, ctx, witness, diag);
3180
3200
} else {
0 commit comments