Skip to content

Commit 1f743b4

Browse files
authored
---
yaml --- r: 343531 b: refs/heads/master-rebranch c: 7897ab8 h: refs/heads/master i: 343529: 3f04900 343527: b3478a3
1 parent 096a549 commit 1f743b4

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 624ad4fcb056378c112345266ffeb03f269fe0bc
1458+
refs/heads/master-rebranch: 7897ab8674b84f9422e13e4d6e301f5eaf527e43
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/lib/Sema/TypeCheckProtocol.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,9 +1927,29 @@ SourceLoc OptionalAdjustment::getOptionalityLoc(TypeRepr *tyR) const {
19271927
return SourceLoc();
19281928
}
19291929

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+
19301951
/// Classify the provided optionality issues for use in diagnostics.
1931-
/// FIXME: Enumify this
1932-
static unsigned classifyOptionalityIssues(
1952+
static OptionalAdjustmentPosition classifyOptionalityIssues(
19331953
const SmallVectorImpl<OptionalAdjustment> &adjustments,
19341954
ValueDecl *requirement) {
19351955
unsigned numParameterAdjustments = 0;
@@ -1942,21 +1962,20 @@ static unsigned classifyOptionalityIssues(
19421962
}
19431963

19441964
if (hasNonParameterAdjustment) {
1945-
// Both return and parameter adjustments.
19461965
if (numParameterAdjustments > 0)
1947-
return 4;
1966+
return OptionalAdjustmentPosition::ParamAndReturn;
19481967

1949-
// The type of a variable.
19501968
if (isa<VarDecl>(requirement))
1951-
return 0;
1969+
return OptionalAdjustmentPosition::VarType;
19521970

1953-
// The result type of something.
1954-
return 1;
1971+
return OptionalAdjustmentPosition::Result;
19551972
}
19561973

19571974
// Only parameter adjustments.
19581975
assert(numParameterAdjustments > 0 && "No adjustments?");
1959-
return numParameterAdjustments == 1 ? 2 : 3;
1976+
return numParameterAdjustments == 1
1977+
? OptionalAdjustmentPosition::Param
1978+
: OptionalAdjustmentPosition::MultipleParam;
19601979
}
19611980

19621981
static void addOptionalityFixIts(
@@ -2076,10 +2095,11 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
20762095

20772096
case MatchKind::OptionalityConflict: {
20782097
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,
20802101
diag::protocol_witness_optionality_conflict,
2081-
classifyOptionalityIssues(adjustments, req),
2082-
withAssocTypes);
2102+
issues, withAssocTypes);
20832103
addOptionalityFixIts(adjustments,
20842104
match.Witness->getASTContext(),
20852105
match.Witness,
@@ -3167,14 +3187,14 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
31673187
auto &diags = ctx.Diags;
31683188
{
31693189
SourceLoc diagLoc = getLocForDiagnosingWitness(conformance,witness);
3190+
auto issues = static_cast<unsigned>(
3191+
classifyOptionalityIssues(adjustments, requirement));
31703192
auto diag = diags.diagnose(
31713193
diagLoc,
31723194
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());
31783198
if (diagLoc == witness->getLoc()) {
31793199
addOptionalityFixIts(adjustments, ctx, witness, diag);
31803200
} else {

0 commit comments

Comments
 (0)