File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -1346,11 +1346,19 @@ namespace {
1346
1346
auto *IP = cast<IsPattern>(item);
1347
1347
switch (IP->getCastKind ()) {
1348
1348
case CheckedCastKind::Coercion:
1349
- case CheckedCastKind::BridgingCoercion:
1349
+ case CheckedCastKind::BridgingCoercion: {
1350
+ // If the pattern and subpattern types are identical than this is a
1351
+ // non-useful cast that we've already warned about, but it also means
1352
+ // this pattern itself is a no-op and we should examine the subpattern.
1353
+ auto *subPattern = IP->getSubPattern ();
1354
+ if (subPattern && IP->getType ()->isEqual (subPattern->getType ()))
1355
+ return projectPattern (TC, subPattern, sawDowngradablePattern);
1356
+
1350
1357
// These coercions are irrefutable. Project with the original type
1351
1358
// instead of the cast's target type to maintain consistency with the
1352
1359
// scrutinee's type.
1353
1360
return Space (IP->getType (), Identifier ());
1361
+ }
1354
1362
case CheckedCastKind::Unresolved:
1355
1363
case CheckedCastKind::ValueCast:
1356
1364
case CheckedCastKind::ArrayDowncast:
Original file line number Diff line number Diff line change @@ -786,3 +786,19 @@ func checkLiteralTuples() {
786
786
default : break
787
787
}
788
788
}
789
+
790
+ func sr6975( ) {
791
+ enum E {
792
+ case a, b
793
+ }
794
+
795
+ let e = E . b
796
+ switch e {
797
+ case . a as E : // expected-warning {{'as' test is always true}}
798
+ print ( " a " )
799
+ case . b: // Valid!
800
+ print ( " b " )
801
+ case . a: // expected-warning {{case is already handled by previous patterns; consider removing it}}
802
+ print ( " second a " )
803
+ }
804
+ }
You can’t perform that action at this time.
0 commit comments