Skip to content

Commit 43cd686

Browse files
committed
Sema: Allow "case let value as [Int]" and remove the diagnostic that it is not implemented
1 parent eb7a23f commit 43cd686

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,16 +1384,7 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
13841384
// Valid checks.
13851385
case CheckedCastKind::ArrayDowncast:
13861386
case CheckedCastKind::DictionaryDowncast:
1387-
case CheckedCastKind::SetDowncast: {
1388-
diags.diagnose(IP->getLoc(),
1389-
diag::isa_collection_downcast_pattern_value_unimplemented,
1390-
IP->getCastType());
1391-
IP->setType(ErrorType::get(Context));
1392-
if (Pattern *sub = IP->getSubPattern())
1393-
sub->forEachVariable([](VarDecl *VD) { VD->setInvalid(); });
1394-
return P;
1395-
}
1396-
1387+
case CheckedCastKind::SetDowncast:
13971388
case CheckedCastKind::ValueCast:
13981389
IP->setCastKind(castKind);
13991390
break;

test/Parse/matching_patterns.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,16 @@ case (let (_, _, _)) + 1:
289289
()
290290
}
291291

292-
// FIXME: We don't currently allow subpatterns for "isa" patterns that
293-
// require interesting conditional downcasts.
292+
// "isa" patterns.
294293
class Base { }
295294
class Derived : Base { }
296295

297296

298297
switch [Derived(), Derived(), Base()] {
299-
case let ds as [Derived]: // expected-error{{collection downcast in cast pattern is not implemented; use an explicit downcast to '[Derived]' instead}}
298+
case let ds as [Derived]:
299+
// expected-warning@-1 {{immutable value 'ds' was never used; consider replacing with '_' or removing it}}
300300
()
301-
case is [Derived]: // expected-error{{collection downcast in cast pattern is not implemented; use an explicit downcast to '[Derived]' instead}}
301+
case is [Derived]:
302302
()
303303

304304
default:

test/SILGen/switch.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,23 @@ func test_isa_class_2(x: B) -> AnyObject {
635635
}
636636
// CHECK: } // end sil function '$s6switch16test_isa_class_21xyXlAA1BC_tF'
637637

638+
// CHECK-LABEL: sil hidden [ossa] @$s6switch14test_isa_array2psySayAA1P_pG_tF : $@convention(thin) (@guaranteed Array<P>) -> () {
639+
func test_isa_array(ps: Array<P>) {
640+
switch ps {
641+
case is [X]:
642+
// CHECK: [[IS_X]]:
643+
a()
644+
case is [Y]:
645+
// CHECK: [[IS_Y]]:
646+
b()
647+
648+
case _:
649+
d()
650+
}
651+
e()
652+
}
653+
// CHECK: } // end sil function '$s6switch14test_isa_array2psySayAA1P_pG_tF'
654+
638655
enum MaybePair {
639656
case Neither
640657
case Left(Int)

0 commit comments

Comments
 (0)