Skip to content

Commit fc982ae

Browse files
committed
[Diagnostics] Use signed integer to store difference in optionality between types
For checked cast coercion warnings let's store difference in optionality as an `int` because it's possible that "to" type is more optional than "from" type.
1 parent 0d50593 commit fc982ae

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7466,7 +7466,7 @@ SourceRange CheckedCastBaseFailure::getCastRange() const {
74667466
llvm_unreachable("There is no other kind of checked cast!");
74677467
}
74687468

7469-
std::tuple<Type, Type, unsigned>
7469+
std::tuple<Type, Type, int>
74707470
CoercibleOptionalCheckedCastFailure::unwrappedTypes() const {
74717471
SmallVector<Type, 4> fromOptionals;
74727472
SmallVector<Type, 4> toOptionals;
@@ -7483,8 +7483,7 @@ bool CoercibleOptionalCheckedCastFailure::diagnoseIfExpr() const {
74837483
return false;
74847484

74857485
Type unwrappedFrom, unwrappedTo;
7486-
unsigned extraFromOptionals;
7487-
std::tie(unwrappedFrom, unwrappedTo, extraFromOptionals) = unwrappedTypes();
7486+
std::tie(unwrappedFrom, unwrappedTo, std::ignore) = unwrappedTypes();
74887487

74897488
SourceRange diagFromRange = getFromRange();
74907489
SourceRange diagToRange = getToRange();
@@ -7515,7 +7514,7 @@ bool CoercibleOptionalCheckedCastFailure::diagnoseForcedCastExpr() const {
75157514
auto fromType = getFromType();
75167515
auto toType = getToType();
75177516
Type unwrappedFrom, unwrappedTo;
7518-
unsigned extraFromOptionals;
7517+
int extraFromOptionals;
75197518
std::tie(unwrappedFrom, unwrappedTo, extraFromOptionals) = unwrappedTypes();
75207519

75217520
SourceRange diagFromRange = getFromRange();
@@ -7558,8 +7557,7 @@ bool CoercibleOptionalCheckedCastFailure::diagnoseConditionalCastExpr() const {
75587557
auto fromType = getFromType();
75597558
auto toType = getToType();
75607559
Type unwrappedFrom, unwrappedTo;
7561-
unsigned extraFromOptionals;
7562-
std::tie(unwrappedFrom, unwrappedTo, extraFromOptionals) = unwrappedTypes();
7560+
std::tie(unwrappedFrom, unwrappedTo, std::ignore) = unwrappedTypes();
75637561

75647562
SourceRange diagFromRange = getFromRange();
75657563
SourceRange diagToRange = getToRange();

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ class CoercibleOptionalCheckedCastFailure final
24962496
bool diagnoseAsError() override;
24972497

24982498
private:
2499-
std::tuple<Type, Type, unsigned> unwrappedTypes() const;
2499+
std::tuple<Type, Type, int> unwrappedTypes() const;
25002500

25012501
bool diagnoseIfExpr() const;
25022502

0 commit comments

Comments
 (0)